Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using wildcards When Searching through service names

178 views
Skip to first unread message

Zebadunc

unread,
Nov 16, 2005, 7:15:07 PM11/16/05
to
i have a script that i need to pull a list of services with
DisplayNames all beginning with 'Sophos'.
the problem is i don't want to to have to do a loop and next each of
the names because they are different depending on the software version.
There is 2 or 5 on some clients and 7 on a server.

The main part of my script goes like this.

strComputer = iComputerName
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery _
("Select * from Win32_Service where DisplayName='Sophos Agent'")
For Each objService In colRunningServices
' Wscript.Echo objService.DisplayName & VbTab & objService.State

If objService.State = "Stopped" Then
objService.StartService()
WScript.Echo objService.DisplayName & " service has been started"

This works okay when specifying a service name but i need to specify
something like this:

("Select * from Win32_Service where DisplayName='%Sophos%") - though
this doesn't work as a wildcard.

I have tried DisplayName<='Sophos' & >='Sophos' - but this returns the
services as well as any preceeding them of before them.
I know ("Select * from Win32_Service) will select all the service names
but is there anything that can be used as a wildcard along with the
text Sophos ? - or can you use
("Select * from Win32_Service) to pull a list and then select only the
sophos services to take an action on ?

thanks in advance

LakeGator

unread,
Nov 16, 2005, 8:17:41 PM11/16/05
to
For a happier time try:

("Select * from Win32_Service where DisplayName LIKE '%Sophos%")

Zebadunc

unread,
Nov 18, 2005, 1:09:43 PM11/18/05
to
thanks for this - it works a treat on XP but when i went to run it on a
windows 2000 client it came up with error null on the line:

For Each objService In colRunningServices

I have narrowed it down to the LIKE and the %% in the line

("Select * from Win32_Service where DisplayName LIKE '%Sophos%'")

Is there another method for 2000 that i could stick an OR statement in,
or do you need to DIM the LIKE or %% variables.?
I have checked and the DisplayName value is present in service
properties on both 2K an XP.

thanks

LakeGator

unread,
Nov 18, 2005, 2:22:36 PM11/18/05
to
The 'right' answer is to upgrade to Windows XP or better but I
guess using a Macintosh is out of the question. Please, excuse the
poor attempt at humor and the comment about the Macintosh, too. (-:

The approach I suggest is to scan all the services and just change the
If statement that decides to alert you to the end of the world as you
once knew it:

If objService.State = "Stopped" And
InStr(objService.DisplayName,"Sophos") > 0Then

Have fun!

0 new messages