views:

17

answers:

3

I have created a service in win32,c++ . I am able to create the service , but when I try to start it, it gives following error.

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

What is the best way to get to the root cause, since this error message is not conveying anything meaningful

A: 

The best way to get the root cause would be to check the SERVICE_STATUS_PROCESS.dwCheckPoint value. Your service is updating that while it's in state START_PENDING, and with sc query you can poll it from the command line.

MSalters
A: 

Please note that if you perform a long operation when you start the service, the error might be from that. SC waits 30 seconds for the starting operation to complete, then reports a failure.

DaeMoohn
A: 

Debugging services is hard. These days I prefer to write a class library that does all the work, a service that just calls one method of the class library, and a test harness (usually a console app) that calls the same method. That way I can run the test harness in the debugger and get most of the errors out of the way.

The two messages you tend to get when your service won't start are the one you just got and the "it started but then stopped" one, which usually means it threw an exception. Yours usually implies a bad loop or an overly long sleep if you're writing a "wake up and see if it's midnight yet" kind of service. But really, running it under the debugger from a test harness is the best way to gain insight into what's happening.

Kate Gregory