0
votes

when creating a windows service that runs any cmd file then trying to start the service, get the following error. “error 1053: the service didn't respond to the start or control request in a timely fashion”

Steps to regenerate the issue:

  1. Run cmd as an admin

  2. sc create test01 binPath="C:\test.cmd"

  3. Create a test.cmd file and put “echo test” in it

  4. Start the test01 service in the windows services list

Googling the issue I got the following fixes:

https://support.microsoft.com/en-au/help/886695/you-receive-an-error-1053-the-service-did-not-respond-to-the-start-or this link recommends installing a hotfix but it’s for 2003 so it didn’t work on windows 10 (I can’t find one for windows 10 )

https://support.threattracksecurity.com/support/solutions/articles/1000071019-error-1053-the-service-did-not-respond-in-a-timely-fashion-when-attempting-to-start-stop-or-pause this link recommends changing the system registry to change the waiting time for a service to start, but when I applied it didn’t take an effect.

2
Try to use the correct syntax to format your code and links.Ethan Yang

2 Answers

0
votes

Win10 service can’t run CMD files direcly if explicit GUI permission is not granted. You may try running cmd.exe in quiet mode and than run “cmd file” by passing it’s path as parameter.

You may read more about running services that may run GUI on MSDN

0
votes

I know it's an old question, but I think others may find the answer useful.

The windows service runtime requires an executable file that calls some Windows API methods to notify the service startup progress, and also to register some callback methods that are invoked when the service is started or stopped by the services snapin.

Since the batch file does not call the Windows API method to notify the startup progress, the service runtime thinks it hang, and it says "error 1053: the service didn't respond to the start or control request in a timely fashion". This error may also happen if the service throws an unhandled exception at startup (due to a missing assembly or malformed config file, for example).

You cannot run a batch file as a windows service. You may create a program in .NET Core with a class that extends ServiceBase and implements the OnStart, OnStop, and OnShutdown virtual methods. This class make all necessary calls to Windows API to allow the program to run as a service.