Start the service
Sc_handle Schscmanager = OpenSCManager (null, NULL, sc_manager_all_access); Create a connection to the Service Control Manager
if (Schscmanager = = NULL)
{
return FALSE;
}
Sc_handle Schservice = OpenService (Schscmanager, _t ("*"), service_all_access | DELETE); Open service, * indicates service name
if (Schservice = = NULL)
{
return FALSE;
}
Service_status Service;
QueryServiceStatus (Schservice, &service);
if (service.dwcurrentstate = = service_stopped)
{
StartService (schservice, 0, NULL);
Closeservicehandle (Schscmanager);
Closeservicehandle (Schservice);
}
Stop Service
Sc_handle Schscmanager = OpenSCManager (null, NULL, sc_manager_all_access);
if (Schscmanager = = NULL)
{
return FALSE;
}
Sc_handle Schservice = OpenService (Schscmanager, _t ("*"), service_all_access | DELETE);
if (Schservice = = NULL)
{
return FALSE;
}
Service_status Service;
QueryServiceStatus (Schservice, &service);
if (service.dwcurrentstate = = service_running)
{
ControlService (Schservice, Service_control_stop, &service);
Closeservicehandle (Schscmanager);
Closeservicehandle (Schservice);
}
Windows Start and stop services