VBScript and WMI to stop and restart a running service

Option Explicit
Dim objWMIService, objItem, objService
Dim colListOfServices, strComputer, strService, intSleep
strComputer = “.”
intSleep = 15000
WScript.Echo “Click OK to begin”

‘On Error Resume Next
‘ strService is case sensitive
strService = ” ‘AdobeARMservice’ ”
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” _
& strComputer & “\root\cimv2”)
Set colListOfServices = objWMIService.ExecQuery _
(“Select * from Win32_Service Where Name =”_
& strService & ” “)
For Each objService in colListOfServices
objService.StopService()
WScript.Echo “The ” & strService & ” service has been stopped”
WScript.Sleep intSleep
objService.StartService()
Next
WScript.Echo “The ” & strService & ” service has Started”
WScript.Quit

Leave a Reply