Hey all, I am using this to check the status of a service:
the problem i have is that the hService comes back with a zero even though i know that the service is there and running. Any ideas? Any way to make it better?
Code:
ServiceStatus = ""
hSManager = OpenSCManager(computername, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS)
If hSManager <> 0 Then
hService = OpenService(hSManager, ServiceName, SERVICE_ALL_ACCESS)
If hService <> 0 Then
hServiceStatus = QueryServiceStatus(hService, ServiceStat)
If hServiceStatus <> 0 Then
Select Case ServiceStat.dwCurrentState
Case SERVICE_STOPPED
ServiceStatus = "Stopped"
Case SERVICE_START_PENDING
ServiceStatus = "Start Pending"
Case SERVICE_STOP_PENDING
ServiceStatus = "Stop Pending"
Case SERVICE_RUNNING
ServiceStatus = "Running"
Case SERVICE_CONTINUE_PENDING
ServiceStatus = "Continue Pending"
Case SERVICE_PAUSE_PENDING
ServiceStatus = "Pause Pending"
Case SERVICE_PAUSED
ServiceStatus = "Paused"
Case Else
ServiceStatus = "Not found"
End Select
End If
CloseServiceHandle hService
End If
CloseServiceHandle hSManager
End If
the problem i have is that the hService comes back with a zero even though i know that the service is there and running. Any ideas? Any way to make it better?