Question

I would like to monitor some services with WMI:
1. Test if the service is running
2. If not running restart it
3. If I can't restart it send an email

Could someone help me deal with this please?

strComputer = "." 
srv= " WSearch, wuauserv "

Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_Service where Name='srv'") 
For Each objService in colItems
Wscript.Echo "Service Name: " & objService.Name & VBNewLine _
    & "State: " & objService.State

     if objService.State="Stopped"  then
     objService.StartService()
    Wscript.Echo "Started service " 
    else 
    REM here the code for email if the service didn't start
 end if         
Next

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top