我想用WMI监控一些服务:
1.测试服务是否正在运行
2.如果没有运行重新启动它
3.如果我无法重新启动,请发送电子邮件
有人可以帮我解决这个问题吗?
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