Windows 7 bat file not starting as a service

六眼飞鱼酱① 提交于 2019-12-07 03:22:48

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/8972679/windows-7-bat-file-not-starting-as-a-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!