Цитата SharkyEXE:
Только , повторюсь , на самом деле работающую службу »
|
SharkyEXE, нет никаких способов гарантированно получить работающую службу. По многим причинам.
Примерно так:
Скрытый текст
Код:
AutoItSetOption("MustDeclareVars", 1)
If RunService("wscsvc") Then
ConsoleWrite("Service running." & @CRLF)
;
; Place your code here
;
Else
ConsoleWrite("Service not running." & @CRLF)
EndIf
Exit(0)
Func RunService($sServiceName)
Local $oSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
Local $oSWbemServicesEx = $oSWbemLocator.ConnectServer(".", "root\cimv2")
Local $oSWbemObjectEx = $oSWbemServicesEx.Get("Win32_Service.Name='" & $sServiceName & "'")
Local $iTimer = 0
Local $bDone = False
Do
Switch $oSWbemObjectEx.State
Case "Running"
ConsoleWrite("Service [" & $sServiceName & "] already running." & @CRLF)
Return True
Case "Stopped"
If $oSWbemObjectEx.StartMode = "Disabled" Then
If Not $oSWbemObjectEx.ChangeStartMode("Manual") = 0 Then
ConsoleWrite("Can't change start mode of service [" & $sServiceName & "] to [Manual]." & @CRLF)
Return False
EndIf
EndIf
If $oSWbemObjectEx.StartService() = 0 Then
ConsoleWrite("Service [" & $sServiceName & "] start successfully." & @CRLF)
Return True
Else
ConsoleWrite("Can't start service [" & $sServiceName & "]." & @CRLF)
Return False
EndIf
Case "Paused"
If $oSWbemObjectEx.ResumeService() = 0 Then
ConsoleWrite("Service [" & $sServiceName & "] resume successfully." & @CRLF)
Return True
Else
ConsoleWrite("Can't resume service [" & $sServiceName & "]." & @CRLF)
Return False
EndIf
Case "Unknown"
ConsoleWrite("Service [" & $sServiceName & "] is unknown state." & @CRLF)
Return False
Case "Start Pending"
Case "Stop Pending"
Case "Continue Pending"
Case "Pause Pending"
EndSwitch
Sleep(100)
$iTimer = $iTimer + 100
Until $iTimer > 60 * 100 * 10
ConsoleWrite("Timer out for pending operation for service [" & $sServiceName & "]." & @CRLF)
Return False
EndFunc