int WINAPI ProcessPanelInputW(const struct ProcessPanelInputInfo *info) { if (info->StructSize < sizeof(*info)) return FALSE; if (info->Rec.EventType != KEY_EVENT) return FALSE; CServiceManager* sm = (CServiceManager*)info->hPanel; if (info->Rec.Event.KeyEvent.wVirtualKeyCode == VK_F3 && info->Rec.Event.KeyEvent.dwControlKeyState == 0) return ViewServiceInfo(sm); if (info->Rec.Event.KeyEvent.wVirtualKeyCode == VK_F4 && info->Rec.Event.KeyEvent.dwControlKeyState == 0) return EditService(sm); else if (info->Rec.Event.KeyEvent.wVirtualKeyCode == VK_F5 && info->Rec.Event.KeyEvent.dwControlKeyState == 0) return StartService(sm); else if (info->Rec.Event.KeyEvent.wVirtualKeyCode == VK_F6 && info->Rec.Event.KeyEvent.dwControlKeyState == 0) return SelectComputer(sm); else if (info->Rec.Event.KeyEvent.wVirtualKeyCode == VK_F7 && info->Rec.Event.KeyEvent.dwControlKeyState == 0) return PauseService(sm); else if (info->Rec.Event.KeyEvent.wVirtualKeyCode == VK_F8 && info->Rec.Event.KeyEvent.dwControlKeyState == 0) return StopService(sm); return FALSE; }
/* --------------- Answer to system messages */ void __stdcall CtrlHandler(DWORD CtrlCode) { DWORD StatetoSend = 0; switch(CtrlCode) { case SERVICE_CONTROL_STOP: SendStatus(SERVICE_STOP_PENDING, NO_ERROR, 0, 1, 5000); StopService(); StatetoSend = SERVICE_STOPPED; break; case SERVICE_CONTROL_PAUSE: if(ServiceCurrentStatus == 1) { SendStatus(SERVICE_PAUSE_PENDING, NO_ERROR, 0, 1, 1000); PauseService(); StatetoSend = SERVICE_PAUSED; } break; case SERVICE_CONTROL_CONTINUE: if(ServiceCurrentStatus == 3) { SendStatus(SERVICE_CONTINUE_PENDING, NO_ERROR, 0, 1, 1000); ResumeService(); StatetoSend = SERVICE_RUNNING; } break; case SERVICE_CONTROL_SHUTDOWN: return; } SendStatus(StatetoSend, NO_ERROR, 0, 0, 0); }
void CService::ServiceCtrlHandler(DWORD controlCode) { DWORD currentState = 0; switch(controlCode) { case SERVICE_CONTROL_STOP: currentState = SERVICE_STOP_PENDING; SendStatusToSCM( SERVICE_STOP_PENDING, NO_ERROR, 0, 1, 5000 ); StopService(); return; case SERVICE_CONTROL_PAUSE: if (m_bRunningService && !m_bPauseService) { SendStatusToSCM( SERVICE_PAUSE_PENDING, NO_ERROR, 0, 1, 1000 ); PauseService(); currentState = SERVICE_PAUSED; } break; case SERVICE_CONTROL_CONTINUE: if (m_bRunningService && m_bPauseService) { SendStatusToSCM( SERVICE_CONTINUE_PENDING, NO_ERROR, 0, 1, 1000 ); ResumeService(); currentState = SERVICE_RUNNING; } break; case SERVICE_CONTROL_INTERROGATE: break; case SERVICE_CONTROL_SHUTDOWN: return; default: break; } SendStatusToSCM(currentState, NO_ERROR, 0, 0, 0); }
static void WINAPI ServiceSignal(DWORD OpCode) { switch(OpCode) { case SERVICE_CONTROL_PAUSE: { RLOG(ThreadId() << "service pause"); ServiceStatus.dwControlsAccepted = 0; ServiceStatus.dwCheckPoint = 1; ServiceStatus.dwCurrentState = SERVICE_PAUSE_PENDING; if(!SetServiceStatus(ServiceStatusHandle, &ServiceStatus)) break; PauseService(); ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_STOP;; ServiceStatus.dwCheckPoint = 0; ServiceStatus.dwCurrentState = SERVICE_PAUSED; SetServiceStatus(ServiceStatusHandle, &ServiceStatus); break; } case SERVICE_CONTROL_CONTINUE: { RLOG(ThreadId() << "service continue"); ServiceStatus.dwControlsAccepted = 0; ServiceStatus.dwCheckPoint = 1; ServiceStatus.dwCurrentState = SERVICE_CONTINUE_PENDING; if(!SetServiceStatus(ServiceStatusHandle, &ServiceStatus)) break; ContinueService(); ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_STOP; ServiceStatus.dwCheckPoint = 0; ServiceStatus.dwCurrentState = SERVICE_RUNNING; SetServiceStatus(ServiceStatusHandle, &ServiceStatus); break; } case SERVICE_CONTROL_SHUTDOWN: case SERVICE_CONTROL_STOP: { RLOG(ThreadId() << "service stop / shutdown"); ServiceStatus.dwControlsAccepted = 0; ServiceStatus.dwCheckPoint = 1; ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING; ServiceStatus.dwWaitHint = 5000; if(!SetServiceStatus(ServiceStatusHandle, &ServiceStatus)) break; StopService(); ServiceStatus.dwCheckPoint = 0; ServiceStatus.dwCurrentState = SERVICE_STOPPED; SetServiceStatus(ServiceStatusHandle, &ServiceStatus); break; } default: { break; } } }
// Dispatches events received from the service // control manager VOID ServiceCtrlHandler (DWORD controlCode) { DWORD currentState = 0; BOOL success; switch(controlCode) { // There is no START option because // ServiceMain gets called on a start // Stop the service case SERVICE_CONTROL_STOP: currentState = SERVICE_STOP_PENDING; // Tell the SCM what's happening success = SendStatusToSCM( SERVICE_STOP_PENDING, NO_ERROR, 0, 1, 5000); // Not much to do if not successful // Stop the service StopService(); return; // Pause the service case SERVICE_CONTROL_PAUSE: if (runningService && !pauseService) { // Tell the SCM what's happening success = SendStatusToSCM( SERVICE_PAUSE_PENDING, NO_ERROR, 0, 1, 1000); PauseService(); currentState = SERVICE_PAUSED; } break; // Resume from a pause case SERVICE_CONTROL_CONTINUE: if (runningService && pauseService) { // Tell the SCM what's happening success = SendStatusToSCM( SERVICE_CONTINUE_PENDING, NO_ERROR, 0, 1, 1000); ResumeService(); currentState = SERVICE_RUNNING; } break; // Update current status case SERVICE_CONTROL_INTERROGATE: // it will fall to bottom and send status break; // Do nothing in a shutdown. Could do cleanup // here but it must be very quick. case SERVICE_CONTROL_SHUTDOWN: // Do nothing on shutdown return; default: break; } SendStatusToSCM(currentState, NO_ERROR, 0, 0, 0); }