https://gist.github.com/the-nose-knows/607dba810fa7fc1db761e4f0ad1fe464
| 29 | |
| 30 | // https://gist.github.com/the-nose-knows/607dba810fa7fc1db761e4f0ad1fe464 |
| 31 | BOOL 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 | } |
no outgoing calls
no test coverage detected