Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 7 bat file not starting as a service

I'm running a Windows service which starts a simple bat-file during start up, but the service won't start. If I try run it manually from the service GUI I get following error message.

Error 1053: the service did not respond to the start or control request in a timely fashion

This seems to be a common error during service startup, however I didn't find similar problem in the other answers. I created the service from command line with following command

C:\Users\Administrator>sc create service_name binpath= c:\service.bat start= auto
[SC] CreateService SUCCESS

Then I run it with

C:\Users\Administrator>sc start service_name

However, I got the error message:

[SC] StartService FAILED 5:

Access is denied.

If I run it from the command prompt as administrator, I don't get the access denied message, but I get the 1053 error. I suppose running one bat file as a Windows service shouldn't be that difficult. Any ideas?

like image 613
BFinn Avatar asked Jan 23 '12 13:01

BFinn


People also ask

How do I run a batch file in Windows 7?

To run a batch file, move to the directory containing the file and type the name of the batch file. For example, if the batch file is named "hope. bat," you'd type "hope" to execute the batch file.


1 Answers

You get the first error because your batch file is unable to negotiate/interact with the Windows Services subsystem. When Windows starts a Service, the OS waits a few seconds for the Service to report that is has started properly. If this signal never arrives (as with your batch file, which doesn't know anything about Services), Windows will report error #1053.

You will need a "wrapper" application to run your batch file as a service. The free "SRVANY" utility from Microsoft may work for you but you should investigate the more fully-featured commercial alternatives as well.

like image 70
CoreTech Avatar answered Oct 15 '22 17:10

CoreTech