Hello,

Facing an issue with a windows service in client's production environement.

They complain the service gets hanged up and they can not shut it down or fail to kill the process. This is their production envoirnment and they can not frequently restart their machine to do that..

I have observed the log file on disk that our service creates,

based on that what I've observed is

When user tries to stop the service from the service panel, the following function gets the control and I hope we can force the service in the following handler to exit even if it is hung somewhere else ...

Please advise,



Thank you,

Ahmed

// some where in code we set this handler using



hServiceStatus = RegisterServiceCtrlHandler(szExeName,(LPHANDLER_FUNCTION)controlHandler);





// Here is the actual handler
void controlHandler(DWORD request)
{
switch(request)
{
case SERVICE_CONTROL_STOP:
serviceStatus.dwWin32ExitCode = 0;
serviceStatus.dwCurrentState = SERVICE_STOPPED;
SetServiceStatus (hServiceStatus, &serviceStatus);
LOG(LOG_WARN, "SERVICE CONTROL", FormatString("Service Stopped"));



// our close open sockets etc..

// Advise Some code to force exit service as it may be hung else where for indefinite time



return;

case SERVICE_CONTROL_SHUTDOWN:
serviceStatus.dwWin32ExitCode = 0;
serviceStatus.dwCurrentState = SERVICE_STOPPED;
SetServiceStatus (hServiceStatus, &serviceStatus);
LOG(LOG_WARN, "SERVICE CONTROL", FormatString("Service Shutdown"));



// Advise Some code to force exit service as it may be hung else where for indefinite time

return;

default:
break;
}

// Report current status
SetServiceStatus (hServiceStatus, &serviceStatus);
return;
}