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
("Select * from Win32_Service where DisplayName LIKE '%Sophos%")
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
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!