Hi there,
I am trying to create a service following the example documented in the link below: http://msdn.microsoft.com/en-us/library/bb540475(v=VS.85).aspx
What I am interested in is to be able to catch user "lock" and "unlock" workstation events.
Using the code on from the example provided, I modified the following:
Line 15:
Original:
VOID WINAPI SvcCtrlHandler( DWORD );
Modified:
DWORD WINAPI SvcCtrlHandler( DWORD, DWORD, LPVOID, LPVOID );
Line 141:
Original:
gSvcStatusHandle = RegisterServiceCtrlHandler( SVCNAME, SvcCtrlHandler);
Modified:
gSvcStatusHandle = RegisterServiceCtrlHandlerEx( SVCNAME, SvcCtrlHandler, NULL);
Line 244:
Original:
gSvcStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
Modified:
gSvcStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_SESSIONCHANGE;
Line 266:
Original:
VOID WINAPI SvcCtrlHandler( DWORD dwCtrl )
{
// Handle the requested control code.
switch(dwCtrl)
{
case SERVICE_CONTROL_STOP:
ReportSvcStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
// Signal the service to stop.
SetEvent(ghSvcStopEvent);
ReportSvcStatus(gSvcStatus.dwCurrentState, NO_ERROR, 0);
return;
case SERVICE_CONTROL_INTERROGATE:
break;
default:
break;
}
}
Modified:
DWORD WINAPI SvcCtrlHandler( DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext )
{
DWORD dwErrorCode = NO_ERROR;
switch(dwControl)
{
case SERVICE_CONTROL_STOP:
ReportSvcStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
// Signal the service to stop.
SetEvent(ghSvcStopEvent);
ReportSvcStatus(gSvcStatus.dwCurrentState, NO_ERROR, 0);
break;
case SERVICE_CONTROL_INTERROGATE:
break;
case SERVICE_CONTROL_SESSIONCHANGE:
ReportSvcStatus(gSvcStatus.dwCurrentState, NO_ERROR, 0);
break;
default:
break;
}
return dwErrorCode;
}
With the changes above, my service compiled and install fine.
I try starting my service on the windows 7 machine, it would start fine (but I will not be able to stop, pause or do anything to the service as all option will be disabled).
I also tried my service on my Windows 2000 machine, it does not even start(it will be stuck on the "starting" status)
My main objective is getting the service to run properly on the Windows 7 environment, getting it backward compatible in Windows 2000 will be a bonus.
Can anyone please advise? Thank you in advance,
Ron