|
|
FAQ
Search
Memberlist
Usergroups
Register
Profile
Private messages
Log in
|
|
| Author |
Message |
Javier Guest
|
Posted: Sat Aug 04, 2007 1:50 am Post subject: Script for monitoring a Service |
|
|
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 |
|
| Back to top |
|
 |
|
|
John R Guest
|
Posted: Sat Aug 04, 2007 4:57 pm Post subject: Re: Script for monitoring a Service |
|
|
"Javier" <Javier@discussions.microsoft.com> wrote in message
news:8CB56AF0-9383-4F61-B01A-754F8BC84C02@microsoft.com...
| Quote: | 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
|
You do know about the options on the 'recovery' tab on the service
properties?
John R |
|
| Back to top |
|
 |
|
|