SC _HANDLE scm, sHandle;
SERVICE_STATUS ServiceStatus;
Scm = OpenSCManager (NULL, NULL, SC _MANAGER_ALL_ACCESS );
If (scm! = NULL)
{
// Start the service
SHandle = OpenService (scm, "GwbnService", SERVICE_START );
If (sHandle! = NULL)
{
StartService (sHandle, 0, NULL) // start Service
}
// Stop the Service
SHandle = OpenService (scm, "GwbnService", SERVICE_STOP | SERVICE_QUERY_STATUS );
If (sHandle! = NULL)
QueryServiceStatus (sHandle, & ServiceStatus );
If (ServiceStatus. dwCurrentState = SERVICE_RUNNING | ServiceStatus. dwCurrentState = SERVICE_PAUSED)
{
ControlService (sHandle, SERVICE_CONTROL_STOP, & ServiceStatus );
}
// Pause the Service
SHandle = OpenService (scm, "GwbnService", SERVICE_PAUSE_CONTINUE | SERVICE_QUERY_STATUS );
If (sHandle! = NULL)
QueryServiceStatus (sHandle, & ServiceStatus );
If (ServiceStatus. dwCurrentState = SERVICE_RUNNING)
{
ControlService (sHandle, SERVICE_CONTROL_PAUSE, & ServiceStatus );
}
// Continue Service
SHandle = OpenService (scm, "GwbnService", SERVICE_PAUSE_CONTINUE | SERVICE_QUERY_STATUS );
If (sHandle! = NULL)
QueryServiceStatus (sHandle, & ServiceStatus );
If (ServiceStatus. dwCurrentState = SERVICE_PAUSED)
{
ControlService (sHandle, SERVICE_CONTROL_CONTINUE, & ServiceStatus );
}
}
Note: The service name and display name are different. The service name is required here.
From: Awey_001 Column