Retrieving and Displaying Properties of a Managed Resource

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

WMI is perhaps best suited for returning information about a computer; there are literally hundreds of WMI classes that provide information on everything from the services installed on a computer to the events recorded in the event logs to attached peripherals such as printers, monitors, and disk drives.

The amount and variety of information that can be returned by using WMI is, in itself, enough to make scripting an important tool for system administration. What makes the technology even more valuable, however, is the fact that the same basic approach can be used to return information regardless of the source. For example, the script template shown in Listing 6.23 returns information about the services installed on a computer. However, this template can easily be adapted to return information about any other managed resource on the computer.

Listing 6.23   Template for Retrieving and Displaying Resource Properties

1 2 3 4 5 6 7 8 9 10 11 12 13 
strComputer = "." strNamespace = "\root\cimv2" strClassName = "Win32_Service" Set objSWbemServices = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & strNamespace) Set colInstances = objSWbemServices.ExecQuery _     ("SELECT * FROM" & strClassName) For Each objInstance in colInstances      Wscript.Echo "Caption "     & objInstance.Caption      Wscript.Echo "Description " & objInstance.Description Next

To use this template with other WMI classes:

  1. Set the value of strClassName to the appropriate WMI class.
  2. If necessary, set the value of strNamespace to the appropriate WMI namespace.
  3. Replace the statements within the For Each loop that echo the properties and their values. Remove the following lines and replace them with the appropriate lines of code for the property values being displayed.
    Wscript.Echo "Caption "     & objInstance.Caption Wscript.Echo "Description " & objInstance.Description 

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