Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


June 2000

Leveraging Windows Management Instrumentation in Win2K Pro


RSS
Subscribe to Windows IT Pro | See More Windows 2000 Professional Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

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.

MANAGEMENT APPLICATIONS
APPMANAGER
NetIQ * 408-330-7000
http://www.netiq.com/products
TIVOLI ENTERPRISE SOLUTIONS
IBM * 512-794-0623
http://www.tivoli.com/products/solutions
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 exist—absolute 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 subset—WBEM Query Language—that 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 methods—Create, 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.

Related Articles in Previous Issues
You can obtain the following articles from Windows 2000 Magazine's Web site at http://www.win2000mag.com/articles.

GREG TODD
"The Future of Systems Management," July 1998, InstantDoc ID 3567
BOB WELLS
Scripting Solutions, "Systems Management Panacea," April 1999, InstantDoc ID 5043
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 (MSI—formerly 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 WMI—you'll be glad you did.

End of Article

   Previous  1  [2]  Next  


Reader Comments

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...


Related Events Deep Dive into Windows Server 2008 R2 presented by John Savill

Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

SQL Server Administration for Oracle DBAs

Related Windows OSs Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement