Identifying the Role of a Computer Based on the Service It Provides

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

The way in which you manage a specific computer depends greatly on the role that computer plays. For example, you generally monitor different aspects of a DNS server than a DHCP server. Although no single property can tell you whether a particular computer is a database server, an e-mail server, or a multimedia server, you can often identify the role a computer plays by identifying the services installed on it.

In large organizations, only one of the major services (such as e-mail) is likely to be installed on a single computer. It would be unusual for a mail server to also perform as a server for Microsoft® Windows Media® technologies player files. Because of this, identifying a service installed on a computer can help identify the computer s role in the network. If the Microsoft® Exchange Server service is installed and running on a computer, it is generally safe to assume that this computer functions as a mail server.

You can use the WMI Win32_Service class to enumerate the services installed on a computer. In addition, you can use this class to determine whether those services are currently running and to return any other required information about that service and how it has been configured.

Note

  • For more information about managing services using WMI, see "Services" in this book.

Scripting Steps

Listing 9.13 contains a script that identifies computer roles based on services installed on the computer. To carry out this task, the script must perform the following steps:

  1. Create a variable to specify the computer name.
  2. Use a GetObject call to connect to the WMI namespace root\cimv2 on the computer, and set the impersonation level to Impersonate.
  3. Use the ExecQuery method to query the Win32_Service class.

    To limit the number of services returned, a Where clause is used to restrict data retrieval to those services with a registry name of MSSQLServer.

  4. Use the Count property to determine the number of services returned.

    The Count property provides a quick way to determine whether any instances of Microsoft® SQL Server are installed on the computer. If the value of the Count property is 0, SQL Server is not installed. If the Count is greater than 0, SQL Server is installed.

  5. Based on the value of the Count property, echo a string reporting whether SQL Server is installed.

    If the service is installed, the script also echoes the current service state, that is, whether the service is running, paused, stopped, or resuming operation.

Listing 9.13   Identifying Computer Roles Based on Services

1 2 3 4 5 6 7 8 9 10 11 12 
strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colServices = objWMIService.ExecQuery _     ("SELECT * FROM Win32_Service WHERE Name = 'MSSQLServer'") If colServices.Count > 0 Then     For Each objService in colServices         Wscript.Echo "SQL Server is " & objService.State & "."     Next Else     Wscript.Echo "SQL Server is not installed on this computer." End If

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

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