Recipe7.8.Searching Services


Recipe 7.8. Searching Services

Problem

You want to find one or more services that match certain criteria.

Solution

Using a graphical user interface

The 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>).

For more on service groups, see Recipe 7.11.


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

Discussion

See Table 7-2 (in Recipe 7.1) for descriptions of the properties of a service.

See Also

Recipe 7.11



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net