Previous Section Table of Contents Next Section

Using the WMI Tools

I've already introduced you to Wbemtest, which is a great way to experiment with WMI and get a feel for what it can do. The WMI Administrative Tools, however, includes the WMI Object Browser, which is an exceptionally cool tool. After downloading and installing the tools, launch the Object Browser from the Start menu. Have it connect to the root/CIMV2 namespace, and provide logon credentials if necessary. You'll see the main screen, shown in Figure 17.7.

Figure 17.7. The main Object Browser screen

graphics/17fig07.jpg

The Browser lets you see all the properties associated with each class. For example, it starts connected to the Win32_ComputerSystem class that represents your entire computer; you can see the properties of the class-such as AutomaticResetBootOption-that govern many aspects of your computer's behavior.

On the Object Browser's Methods tab, shown in Figure 17.8, you can see the actions that the class can perform. The Win32_ComputerSystem class, for example, offers a JoinDomainOrWorkgroup method, a Rename method, a SetPowerState method, and an UnjoinDomainOrWorkgroup method. These methods can be programmatically called from within your scripts (which I'll explore in the next two chapters), allowing you to change the computer's configuration.

Figure 17.8. Examining the methods of a WMI class

graphics/17fig08.jpg

How can the Object Browser help you write WMI scripts? The Object Browser provides an easy way to see what's lurking under the hood of WMI. I've always said that the toughest part about using WMI lies in figuring out what the heck you're going to query or change; Object Browser makes it a bit easier to figure out what classes, properties, and methods you want to work with.

Scriptomatic

There's one more WMI tool that I want to introduce: The WMI Scriptomatic. This handy tool was written by Microsoft's "Scripting Guys," who write a regular scripting column on Microsoft's TechNet Web site. You can download the Scriptomatic from http://www.microsoft.com/downloads/details.aspx?displaylang=en&familyid=9ef05cbd-c1c5-41e7-9da8-212c414a7ab0. Or, just go to the Microsoft home page, click Downloads, and look through the downloads until you find the Scriptomatic.

The Scriptomatic performs a function very similar to the WMI Query Wizard in PrimalScript, the script editor I use (available from www.sapien.com). You just pick a WMI class-like Win32_ComputerSystem-and the tool produces a template script that queries the class and displays all of its properties. It's a handy way to quickly see the appropriate syntax for a WMI query, but if you look at a couple of different classes you'll realize something very important: All of the scripts produced by the Scriptomatic (and the WMI Query Wizard in PrimalScript) look nearly identical. All that changes is the class name being queried, and the property names being displayed. That's because querying WMI isn't complicated! One simple, generic script-like the one I showed you in Listing 17.1-can be easily modified to query almost anything from WMI.

    Previous Section Table of Contents Next Section