Hi Martin
i know you asked about using WMI. But I use a custom sensor VBS Script I adapted to check if a process is running which shouldn't (in our case dropbox.exe)
I am quite sure you can use this to check if the service is not running.
regards
Thomas
on error resume next
' Commandline Argument is process.exe
' ex: cscript getprocess.vbs explorer.exe
' **************************************
strComputer = "."
if isNull(WScript.Arguments.Item(0)) then
wscript.echo "Process not given -> getprocess.vbs processname.exe"
wscript.quit
else
strProcess = WScript.Arguments.Item(0)
end if
strComputer = WScript.Arguments.Item(1)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery( _
"Select * from Win32_Process WHERE name ='"&strProcess&"'")
if colItems.Count < 1 then
Wscript.Echo colItems.Count&":Ok"
Wscript.quit("0")
ELSE
wscript.echo colItems.Count&":processes running"
wscript.quit("1")
end if
Add comment