Comprobar y reiniciar servicio – WMI VBS script

Un pequeño script muy muy simple para comprobar el estado de un servicio en windows (lo comprobamos por el nombre) y reiniciarlo en el caso de que este caído.


Option Explicit
Dim objWMIService, objItem, objService, strServiceList
Dim colListOfServices, strComputer, strService
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service ")
For Each objService in colListOfServices
strServiceList = strServiceList & vbCr & _ objService.name
if objService.name = "NOMBRE_SERVICIO_A_CONTROLAR" Then
if objService.State = "Stopped" Then
objService.StartService()
End if
End if
Next
'objService.name
'objService.State
'objService.StartService()

Fuentes:

Leave a Reply

Your email address will not be published. Required fields are marked *