Hello There
I am writing a script to query for services of a particular name, at this
stage I am just echoing out the status of the service, this so far is
working, I then tried to catch it when the query found no services, and so
far I cant.
I have fudged it together with a count but I really don't want to leave it
like that, so I was hoping someone could have a look at it for me and tell
how I could do it better
Just remove the % for it not to find the Print service
<SNIP>
SERVICE_NAME = "Print%"
Count = 0
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where DisplayName Like '" &
SERVICE_NAME & "'")
For Each objService in colServiceList
Count = Count +1
Next
If Count > 0 Then
For Each objService in colServiceList
Wscript.Echo objService.State
Next
Else
Wscript.Echo "No Service Found"
END IF
</SNIP>
TIA