up vote 4 down vote favorite
2
share [g+] share [fb]

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!

link|improve this question
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
feedback

5 Answers

up vote 5 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.

link|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. – user2368 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
feedback

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.

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

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.

link|improve this answer
feedback

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.

link|improve this answer
feedback

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.

link|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
feedback

Your Answer

 
or
required, but never shown

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