1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| Function StartService(ServiceName,Computer)
If bDebug = True Then
wscript.echo "Service Name= " & ServiceName
End If
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Service where Name='" & ServiceName & "'")
For each objService in colServiceList
If objService.State <> "Running" Then
If bDebug=True Then
Wscript.Echo "Starting " & ServiceName & " ..."
End If
errReturn = objService.StartService()
If errReturn <> 0 Then
WScript.Echo "Error starting " & ServiceName
StartService = errReturn
Else
Do
Set colRunningServices = objWMIService.ExecQuery ("Select * from Win32_Service where Name='" & ServiceName & "'")
For Each objRunningService In colRunningServices
If objRunningService.State = "Running" Then
If bDebug=True Then
wscript.echo ServiceName & " started."
End If
StartService = 0
Exit Do
Else
wscript.sleep 100
End If
Next
Loop
End If
End If
Next |
Partager