Start or stop a Windows service on the specified computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer & "
ootcimv2")
strService = "Spooler"
Set colListOfServices = objWMIService.ExecQuery _
("SELECT * FROM Win32_Service WHERE Name = '" & strService & "'")
For Each objService in colListOfServices
'Only act on service if not disabled
If NOT objService.StartMode = "Disabled" Then
'Stop Service
returnCode = objService.StopService()
WScript.Sleep 5000
'Start Service
returnCode = objService.StartService()
If returnCode <> 0 Then
'Test code below
Wscript.Echo "Error " & returnCode
End If
End If
Next