The service did not respond to a launch or control request in a timely manner

I created a service in win32, C ++. I can create a service, but when I try to start it, it gives the following error.

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

What is the best way to get to the root cause, as this error message does not convey anything meaningful

+3
source share
5 answers

Debugging services are complicated. 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 test posting (usually a console application) that calls the same method. Thus, I can run the test harness in the debugger and fix most of the errors.

The two messages that you receive when your service does not start is the one you just received and “it was started but then stopped,” which usually means that it threw an exception. Usually you mean a bad loop or a too long dream if you write “wake up” and see if it is still midnight. ”But really, running it under the debugger from the test harness is the best way to find out what is happening.

+3

, , .

, , .

:

...

, , StartServiceCtrlDispatcherW SERVICE_TABLE_ENTRY, .

, SC, , SC , .

:

void CServiceManager::Start(DWORD _dwArgc, LPWSTR * _argv)
{
    // Your performing code.
    // ....

    ::SetServiceStatus(SERVICE_RUNNING); // Roughly

    // Prevent CServiceManager::Start from returning.
    ::WaitForSingleObject(YourExitEvent, 0); 
}

SERVICE_STOPPPED SetEvent .

+3

, , . SC 30 , .

+1

- SERVICE_STATUS_PROCESS.dwCheckPoint. , START_PENDING, sc query .

0

, Windows, MinGW (). MinGW-64

0

Source: https://habr.com/ru/post/1761889/


All Articles