Recipe 7.8. Searching ServicesProblemYou want to find one or more services that match certain criteria. SolutionUsing a graphical user interfaceThe Services snap-in does not allow you to search services. Using a command-line interface:With the sc.exe command you can query against service type (type= <TypeName>), state (state= <State>), and group (group= <GroupName>).
Here are two examples: > sc <ServerName> query state= active > sc <ServerName> query type= driver The psservice.exe command is very similar; you can query against service type (type= <TypeName>), state (state= <State>), and group (group= <GroupName>). For example: > psservice \\<ServerName> query -s active > psservice \\<ServerName> query -t driver Using VBScript' This code queries services based on the specified ' property name and value ' ------ SCRIPT CONFIGURATION ------ strPropName = "State" strPropValue = "'Running'" ' e.g., strComputer = "<ServerName>" ' e.g., fs-rtp01 (use . for local server) ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colServices = objWMI.ExecQuery _ ("Select * from Win32_Service Where " & _ strPropName & " = " & strPropValue) for each objService in colServices Wscript.Echo objService.DisplayName next ' List of Win32_Service properties: ' boolean AcceptPause ' boolean AcceptStop ' string Caption ' uint32 CheckPoint; ' string CreationClassName ' string Description ' boolean DesktopInteract ' string DisplayName ' string ErrorControl ' uint32 ExitCode ' datetime InstallDate ' string Name ' string PathName ' uint32 ProcessId ' uint32 ServiceSpecificExitCode ' string ServiceType ' boolean Started ' string StartMode ' string StartName ' string State ' string Status ' string SystemCreationClassName ' string SystemName ' uint32 TagId ' uint32 WaitHint DiscussionSee Table 7-2 (in Recipe 7.1) for descriptions of the properties of a service. See AlsoRecipe 7.11 |