/build/static/layout/Breadcrumb_cap_w.png
01/05/2010 2312 views
Hi,

I am using the below script to find a specific service which was not running.


strComputer = "."
Set objSWbemServices = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colSWbemObjectSet = objSWbemServices.ExecQuery("SELECT * FROM Win32_Service where state !='Running' and DisplayName = 'Oracleservicetest'")
For Each objSWbemObject In colSWbemObjectSet
WScript.Echo "Display Name: " & objSWbemObject.DisplayName & vbCrLf & _
" State: " & objSWbemObject.State & vbCrLf & _
" Start Mode: " & objSWbemObject.StartMode & vbCrLf
Next



I would like to see some other service also like netlogon.

I tried this but not working.
SELECT * FROM Win32_Service where state !='Running' and DisplayName in ('Oracleservicetest' ,'netlogon')

Please help.
0 Comments   [ + ] Show comments

Comments


Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

All Answers

0
I guess you could loop through an array of service display names (like below) or just use 'OR' clauses in your SQL like this:

Set colSWbemObjectSet = objSWbemServices.ExecQuery("SELECT * FROM Win32_Service WHERE state !='Running' AND (DisplayName = 'Oracleservicetest' OR DisplayName = 'netlogon')")

Dim serviceArray(1)
serviceArray(0) = "Oracleservicetest"
serviceArray(1) = "netlogon"

Dim i : i = 0
Dim strComputer : strComputer = "."
Dim serviceDisplayName : serviceDisplayName = ""

Set objSWbemServices = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

For Each serviceDisplayName In serviceArray

Set colSWbemObjectSet = objSWbemServices.ExecQuery("SELECT * FROM Win32_Service WHERE state !='Running' AND DisplayName = '" & serviceDisplayName & "'")
For Each objSWbemObject In colSWbemObjectSet
WScript.Echo "Display Name: " & objSWbemObject.DisplayName & vbCrLf & _
" State: " & objSWbemObject.State & vbCrLf & _
" Start Mode: " & objSWbemObject.StartMode & vbCrLf
Next
Set colSWbemObjectSet = Nothing
Next

Set objSWbemServices = Nothing
Answered 01/06/2010 by: captain_planet
Black Belt

0
Hi Captain,

Thanks for the scripts. It works fine like a charm.

Actually my request is to send mail to my mail id if any of the services fails to run or it is not running. Please guide me in this.
Answered 01/07/2010 by: nokiak810
Senior Yellow Belt

0
Answered 01/08/2010 by: VBScab
Red Belt