Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I've created the service using

sc create myService binpath=myservice.bat

But when I start it, it fails with the following error message:

[SC] StartService FAILED 1053:
    The service did not respond to the start or control request in a timely fashion.

On Win2k3 I used the srvany.exe from the Resource kit, but there's no resource kit for win2k8. For the time being I've installed the srvany.exe on my machine, but I don't think that's the best way to do it.

Thanks!

share|improve this question
1  
You can run a batch file as a service? Wouldn't a scheduled task be better? I know if you use an actual Windows Service, the OnLoad event needs to return within a few seconds. –  tsilb Aug 16 '09 at 8:29

9 Answers 9

up vote 8 down vote accepted

Of course you can't run a service like that. Did you try using srvany in server 2008? As far as I know there is no 'official' version of srvany for s2k8, but you can always try, can you not?

EDIT: Oh, I forgot! We also use FireDaemon to run non-service applications as services. Though, it is not free and its functionality is a bit too much for your needs.

share|improve this answer
    
Which is what I wrote I did. –  abyx Aug 16 '09 at 7:51
    
hmm.. this is weird. It just filtered right through my brain. Sorry. Either way, srvany seems like the best thing to do in this situation. –  shylent Aug 16 '09 at 8:21
    
srvany works in 2008 (I use it to install and run Winamp.exe as a service on a home server)... but you can't run just a bat file. –  Oskar Duveborn Aug 17 '09 at 7:33
    
srvany it is! Thanks –  abyx Aug 17 '09 at 10:41

Use NSSM to run a .BAT or any old .EXE file as a service. It is almost a replacement for SRVANY and is a no frill no fuss application.

http://iain.cx/src/nssm/

I had the same problem as you, and NSSM was the only utility that worked.

share|improve this answer
3  
I hadn't heard of this before, but it appears to be a valuable tool. Thanks for the tip. –  Skyhawk Aug 24 '10 at 22:13

You can't just run a .BAT file or any old .EXE file as a service. Windows services don't work that you. You can use a utility like the non-Sucking Service Manager (NSSM) or Microsoft's non-free SRVANY utility to run an arbitrary program as a service, but you may find that you don't get very "graceful" stopping behavior.

share|improve this answer

The SC command just adds the required registry entries for a service - if the file you specify isn't a valid service exe it won't turn it into one.

share|improve this answer

We use Task Scheduler to run task whenever the computer starts (regardless a user is logged in or not)

share|improve this answer

from: this post on technet forums: http://social.technet.microsoft.com/Forums/en-US/winserverMigration/thread/98a97aee-c62b-4683-94ab-3777899cf7de/

Here's what to do ...

At the time of this posting, there is no Windows Server 2008 Resource Kit Tools, so get the "srvany.exe " from the "Windows Server 2003 Resource Kit Tools " and copy it to a suitable location on your Win2008 server (e.g. C:\Windows\System32\ ). Use "sc " to create a new service that launches "srvany " (e.g. sc create MyService binPath= C:\Windows\System32\srvany.exe DisplayName= "My Custom Service" ) Using RegEdit : create a "Parameters " key for your service (e.g. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyService\Paramaters\ ) Using RegEdit : within the newly created "Parameters " key , create a string value called "Application " and enter the full path to the application you are wanting to run as a service. (No quotes required.)

And that should do it.

Note : some applications store their settings in a user hive, not under HKEY_LOCAL_MACHINE, so you will need to run the application to configure it, and then configure the service to run as that user.

share|improve this answer

I found two other options that won't have you reaching for your wallet.

You can have sc launch srvany which then points to your program. (there's a forum post that I can't link to because I don't have enough rep here though I do on stackoverflow - grumble) Here are the steps that the original poster used:

  1. Use "sc " to create a new service that launches "srvany " (e.g. sc create MyService binPath= C:\Windows\System32\srvany.exe DisplayName= "My Custom Service" )
  2. Using RegEdit : create a "Parameters " key for your service (e.g. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyService\Paramaters\ )
  3. Using RegEdit : within the newly created "Parameters " key , create a string value called "Application " and enter the full path to the application you are wanting to run as a service. (No quotes required.)

If that seems like a bit of a hack, then you can build a .NET service to launch your process. If you want to skip a few steps, here's an open source .NET service that can launch generic processes:

http://www.codeproject.com/KB/system/xyntservice.aspx

Tweak it to your needs but it'll do most of what you want out of the box.

share|improve this answer
    
And is the srvany that you mention, the one from Win2k3 that has no supported version for Win2k8? –  LarsH Oct 27 '11 at 14:18

I stumbled upon this thing. Here is the tool called Bat_To_Exe_Converter. It's very very easy to convert any .bat files to .exe files. Try it. Download downloader first and it will download the Bat_To_Exe_Converter automatically then. It really helped me to create service which runs my .bat file through .exe. http://download.cnet.com/Bat-To-Exe-Converter/3001-2069_4-10555897.html?spi=eae5ab48292cc101b5f0ec370cf99ad0

share|improve this answer
    
Welcome to Server Fault! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. –  Scott Pack Jul 8 '13 at 17:40

try this... it worked for me..

sc create ServiceTest binpath= "C:\Windows\System32\cmd.exe /C C:\ServiceTest\Jenkins-Slave.bat"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.