=====Versie 2=====
'RestartServices.vbs
'Voor het stoppen en starten van services.
'Win32_Service: http://msdn.microsoft.com/en-us/library/aa394418(VS.85).aspx
'20100720, v1.
'20100721, v2:
'Functie voorzien van intWaitTime parameter om de wachttijd na het stoppen in te kunnen stellen.
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'Functie: RestartService
'Parameter1: display name van de service (string).
'Parameter2: de wachttijd in miliseconde voor het opnieuw starten van de service.
Function RestartService(strServiceDisplayName, intWaitTime)
Set colServices = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE DisplayName = '" & strServiceDisplayName & "'")
For Each objService In colServices
objService.StopService()
WScript.Sleep intWaitTime
objService.StartService()
Next
Set colServices = Nothing
End Function
RestartService "Print Spooler", 5 * 60 * 1000
Set objWMIService = Nothing
=====Versie 1=====
'RestartServices.vbs
'Voor het stoppen en starten van één of meerdere services.
'Win32_Service: http://msdn.microsoft.com/en-us/library/aa394418(VS.85).aspx
'20100720, v1.
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Function RestartService(strServiceDisplayName)
Set colServices = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE DisplayName = '" & strServiceDisplayName & "'")
For Each objService In colServices
objService.StopService()
WScript.Sleep 120000
objService.StartService()
WScript.Sleep 30000
objService.StartService()
Next
Set colServices = Nothing
End Function
RestartService("Print Spooler")
Set objWMIService = Nothing