MCPcopy Create free account
hub / github.com/dobin/RedEdr / IsServiceRunning

Function IsServiceRunning

RedEdr/serviceutils.cpp:31–56  ·  view source on GitHub ↗

https://gist.github.com/the-nose-knows/607dba810fa7fc1db761e4f0ad1fe464

Source from the content-addressed store, hash-verified

29
30// https://gist.github.com/the-nose-knows/607dba810fa7fc1db761e4f0ad1fe464
31BOOL IsServiceRunning(LPCWSTR driverName) {
32 SC_HANDLE scm = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CONNECT);
33 if (scm == NULL)
34 return false;
35 LPCWSTR lpServiceName = driverName;
36
37 SC_HANDLE hService = OpenService(scm, lpServiceName, GENERIC_READ);
38 if (hService == NULL)
39 {
40 CloseServiceHandle(scm);
41 return false;
42 }
43
44 SERVICE_STATUS status;
45 LPSERVICE_STATUS pstatus = &status;
46 if (QueryServiceStatus(hService, pstatus) == 0)
47 {
48 CloseServiceHandle(hService);
49 CloseServiceHandle(scm);
50 return false;
51 }
52
53 CloseServiceHandle(hService);
54 CloseServiceHandle(scm);
55 return (status.dwCurrentState == SERVICE_RUNNING) ? (true) : (false);
56}

Callers 2

StartThePplServiceFunction · 0.85
ManagerStartFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected