This documentation is archived and is not being maintained.
Utility Spotlight WMI Code Creator
Chris Scoville is a programming writer in the Windows Server Developer Documentation group at Microsoft. He writes documentation and code examples for management technologies. He developed the WMI Code Creator tool. Chris can be reached at email@example.com
© 2008 Microsoft Corporation and CMP Media, LLC. All rights reserved; reproduction in part or in whole without permission is prohibited.
Download the code for this article: WMI Code Creator (122KB)
As a systems administrator you’re surely no stranger to Windows®Management Instrumentation (WMI), which gives you access to a wealth of management information and allows you to automate administrative tasks. To take full advantage of WMI you have to write queries to extract the information you need. And if you don’t have the ready-made queries already floating around in your head, you just might want to take the WMI Code Creator for a spin. It’s a recently released tool that generates custom code to use WMI so you can get the most from the myriad of computer management options that WMI has to offer.
The WMI Code Creator can generate code in VBScript, C#, and Visual Basic® .NET; you can run the code directly from the tool. You can generate code to query for management information, execute a management task, or receive event notifications.
For example, suppose you want to get a list of all the services running on a computer. You can use the WMI Code Creator to query for this information by selecting the WMI class you want to query (Win32_Service) and the properties that contain the information you are interested in accessing. And you can do more than just execute queries. Let’s say you want to start a service that isn’t running. You can use the WMI Code Creator to generate a script to do that too. All the code is generated for you based on a few selections you make. Plus, the tool contains step-by-step help to teach you how to use it to get the information you want.
The WMI Code Creator generates code that you can point at remote computers as well. You can query for the same kind of data you can get on local computers, receive event notifications, and even execute tasks remotely. All you need to do is enter the domain and name of the remote computer, and the code is generated automatically.
Figure 1 shows an example of event notification code generated by the WMI Code Creator. Note that you can set the frequency at which WMI should poll for the specified events, and you can edit or execute the code as well.
Figure 1 WMI Code Creator Generating Event Notification Code
If you aren’t familiar with all of the WMI classes and their uses, the WMI Code Creator lets you browse through the available WMI classes on your computer, and displays descriptions of these classes, their properties, and methods. The WMI Code Creator also lets you quickly access the documentation for a WMI class by linking you to the specific class page in the MSDN® WMI documentation online.
The WMI Code Creator download also includes the source code, which serves as a really handy tool for learning how to use the System.Management classes in the Microsoft® .NET Framework to access WMI. The tool was built using WMI, and the source code provides many examples for how to use WMI to add functionality to an application.
Use the tool to open up a world of WMI functionality and all the computer management possibilities it provides. It will save you time writing administrative scripts and code, and provide you with excellent examples and solutions. You can download the utility from WMI Code Creator.