When you install the WMI SDK, you have more tools that you can use to navigate the WMI namespace. The WMI SDK provides the Web browser-based WMI Object Browser, which lets you view objects and their associated methods and properties within the namespace in a nicely formatted, graphical frames-based view. The WMI Object Browser in Screen 5 shows an instance of the Win32_OperatingSystem class, which has the SAUTERNES name property. The window's right-hand pane displays the properties associated with the Win32_OperatingSystem class instance, which is information that is related to my Win2K Pro installation.
The WMI SDK also provides an Event Registration Tool, which you use to manually register a consumer application for particular events, as well as the corresponding WMI Event Viewer that lets you view current event registrations for several consumers. When you register for an event, you create three characteristics for that event registration. First, register the consumer application, which is the application that will receive the event notifications. Next, create a filter that controls what data you want to receive notifications on. For example, you might create a filter to notify you when your processor utilization exceeds 80 percent. Finally, set a timer. Two types of timers existabsolute and interval. The absolute timer lets you set the date and time for when you want the event collection to begin. The interval timer lets you set how frequently you want to poll a WMI provider for data.
WBEM Query Language
WBEM Query Language is the standard language that you use to perform queries against WMI. For example, to create a filter that tells the CIMOM which events you want to register, you need to submit a query for the events to monitor. That query uses a specialized SQL dialect subsetWBEM Query Languagethat is specific to WMI. If you're familiar with SQL, then you'll find using WBEM Query Language easy. However, WBEM Query Language is a read-only query language, so you can use WBEM Query Language to query managed objects, but not to modify them.
WBEM Query Language queries can be data, event, or schema queries. You use data queries to retrieve instances of a specific managed object class and associated properties, and you use event queries to create a filter for a particular event. Schema queries let you extract information (e.g., descriptions of a class and its given methods, properties, and association) about the WBEM schema. The WMI SDK includes more detailed information about the keywords that WBEM Query Language supports. The SDK describes the WMI-specific dialect within WBEM Query Language, but the WMI syntax is similar to SQL.
WMI Scripting
The data types that WMI provides and the ways you can interact with that data are almost limitless. However, I've described consumers of this data as management applications, such as those applications you can get from NetIQ (AppManager) and IBM (Tivoli Enterprise Solutions). For information about AppManager and Tivoli, see "Management Applications."
Microsoft also provides a way for systems administrators to access this data. For example, the WMI Scripting API tool provides COM-based objects, methods, and properties that you can access from Visual Basic (VB), VBScript, JScript, or any other COM-based scripting engine. WMI implements the WMI Scripting API in the CIMOM; when you write a WMI script, you talk to the CIMOM directly, which queries a provider or the repository. You use WMI scripting to register for events, query (through WBEM Query Language) the properties of an object, or change an object's configuration. You can also use WMI scripting to query and manipulate WMI information on remote machines.
The WMI Scripting API tool lets you perform tasks that you wouldn't use a systems management application to perform. For example, in WMI, an instance of the class Win32_Process represents the Win32 processes running on a workstation. You can run the WMI Object Browser from the SDK, connect to the \root\CIMV2 namespace, and select the Browse for Instance button. You then select Win32_Process to display a list of all running processes on the system, as Screen 6 shows. In the example in Screen 6, I've browsed to an instance of notepad.exe to display the properties associated with this instance, including memory and pagefile usage, which the window's right-hand pane shows. Each instance of class Win32_Process supports four methodsCreate, GetOwner, GetOwnerSid, and Terminate.
The code snippet that Figure 1 shows is an example of how you can search for and shut down an instance of Microsoft Word running on a system. In this code, I use a FOR...EACH loop to enumerate a system's running processes. In Figure 1, the GetObject method opens the WMI namespace, which defaults to \root\CIMV2, and sets the impersonation level. WMI uses the currently logged-on user (or another explicitly specified user) to support impersonation to perform a request. When I specify impersonationLevel=impersonate, I'm telling the script to use my existing credentials to connect to the namespace. The next set of commands, ExecQuery("select * from Win32_Process where Name='winword.exe' "), is a WBEM Query Language statement that means to select all instances of the class Win32_process in which the Name property for that instance is equal to winword.exe. After you find the process you're searching for, execute the Terminate method to shut down the process.
Figure 1 shows only a small sample of what you can do with WMI scripting. You can also gather hardware information on local or remote systems, read and change Registry entries, and query the status of an application that includes the Microsoft Installer (MSIformerly Windows Installer). You can check out sample WMI scripts in the
Microsoft Windows 2000 Resource Kit. Several excellent Web sites are also available as resources for Windows Script Host (WSH) and for samples of how you can use WMI, including Gunter Born's Windows Scripting Host Bazaar (http://ourworld.compuserve.com/homepages/ guenter_born/wshbazaar/wshbazaar.htm), Ian Morrish's WSH FAQ (http://wsh.glazier.co.nz), and Clarence Washington Jr.'s Win32 Scripting (http://cwashington.netreach.net/main_site/default.asp).
New Management Visibility with WMI
WMI in Win2K Pro gives you unsurpassed control over your Windows systems and data management. When you leverage WMI and WMI Scripting APIs in your Web pages and scripts, you can create management solutions that take charge of your Win2K infrastructure. I encourage any systems administrator who plans to deploy Win2K to learn about WMIyou'll be glad you did.