I'm writing a service application that sometimes cannot be stopped immediately upon receiving the SERVICE_CONTROL_STOP from the Services MMC. I currently handle it like this: (in pseudo-code):
DWORD
HandlerEx(
DWORD dwControl,
DWORD dwEventType,
PVOID pvEventData,
PVOID pvContext
)
{
switch( dwControl )
{
case SERVICE_CONTROL_STOP:
if ( CanStopServiceNow() )
{
ReportStatus( SERVICE_STOP_PENDING );
DoStopService();
ReportStatus( SERVICE_STOPPED );
return NO_ERROR;
}
else
return ERROR_BUSY;
break;
}
return NO_ERROR;
}
It works well when the service can stop ( and it does stop), but when it cannot stop, I would expect Windows to report the error I'm returning (ERROR_BUSY in this example.) Instead, Windows displays a message saying:
"The service did not return an error.
This could be an internal Windows error or an internal service error."
So my question is, how to make the service report back to SCM that it cannot stop now and make MMC display a message about the actual error code that I'm returning?