Ragazzi, ho urgente bisogno di gestire un servizio, intendo start,stop,pausa ect...
io ho realizzato una funzione:
codice:Public Function ServiceStatus(ServiceName As String) As String Dim ServiceStat As SERVICE_STATUS Dim hSManager As Long Dim hService As Long Dim hServiceStatus As Long Dim a As Long On Error Resume Next ServiceStatus = "" hSManager = OpenSCManager(vbNullString, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS) If hSManager <> 0 Then hService = OpenService(hSManager, ServiceName, SERVICE_ACTIVE) 'ServiceName, SERVICE_ALL_ACCESS) If hService <> 0 Then 'dovrebbe bloccare il servizio a = ControlService(hService, SERVICE_STOP, ServiceStat) 'dovrebbe cercare il servizio hServiceStatus = QueryServiceStatus(CLng(hService), ServiceStat) /////IL PROB STA NEL FATTO CHE QUESTE DUE API NON FANNO QUELLO CHE DOVREBBERO.DOVE SBAGLIO?////// 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 = "Coninue Pending" Case SERVICE_PAUSE_PENDING ServiceStatus = "Pause Pending" Case SERVICE_PAUSED ServiceStatus = "Paused" End Select End If CloseServiceHandle hService End If CloseServiceHandle hSManager End If End Function
Naturalmente ho dichiarato tutti i tipi necessari etc etc ...


Rispondi quotando