I've been working almost three months on a script, it starts the service when
I executed it, but I need a script that runs all the time and checks the
service status, like a endless loop. the language I'm using it's VBscript,
this is the code. besides all I wanna do is that this script check the
service status every 1 milisecond and if the service is stopped then the
script starts the service.
Option Explicit
Dim objWMIService, objItem, objService
Dim colListOfServices, strComputer, strService, intSleep
strComputer = "."
intSleep = 1000
strService = " 'Messenger' "
Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from
Win32_Service Where State = 'Stopped' and Name = 'Messenger'")
For Each objService in colListOfServices
WSCript.Sleep intSleep
objService.StartService()
Next
WScript.Echo "Your "& strService & " service has Started"
WScript.Quit
' End of Example WMI script to Start / Stop services
|