![]() |
Table of Contents |
![]() |
Determining What to QueryI mentioned in the previous chapter that actually figuring out which WMI class to query is the truly tough part about working with WMI, and it's true. The Microsoft MSDN Library reference to the WMI classes, particularly Microsoft's Win32 classes, is the most comprehensive and useful place to start looking. The documentation can be found online at http://msdn.microsoft.com/library. Just expand Setup and System Administration in the left-hand menu, then navigate to Windows Management Instrumentation, SDK Documentation, WMI Reference, WMI Classes, and Win32Classes. Microsoft currently divides the classes into five categories, although that will almost certainly change over time as the classes are expanded. The current categories are
After you've narrowed down the proper category, my best advice is to dive into the documentation and scroll through the class names until you find one that looks like it will do what you want. Need to force a hard drive to run CHKDSK? Hard drives are hardware, but CHKDSK is Windows-specific. After all, you don't really run CHKDSK on a hard drive, do you? You run it on a volume, which is a Windows thing. So, start with the Operating System category. There's the Win32_LogicalDisk category, which represents a volume like C: or D:. Lo and behold, it has a ChkDsk method and a ScheduleAutoChk method, one of which is sure to do the trick. The documentation also helpfully notes that the method is included only in Windows XP and Windows Server 2003, meaning that you'll have to find another way to handle earlier clients. Microsoft's categorization of the WMI classes is far from consistent. For example, Win32_NetworkAdapterConfiguration is included in the Computer System Hardware category. Although I agree that a network adapter is definitely hardware, surely its actual configuration is part of the operating system, right? In other words, be prepared to do a little browsing to find the right classes, especially until you become accustomed to them. TIP The Appendix of this book is a Quick Script Reference I put together to help you locate the right WMI classes more quickly. For example, if you need to write a WMI query to retrieve Windows Product Activation information, just look up "Activation" in the Quick Script Reference. You'll see a reference to WMI, an indication that it's covered in Chapters 17 through 19, and the specific classes involved: Win32_WindowsProductActivation, for example. No matter what, don't get discouraged. Keep browsing through the list until you find what you want. Just so you know, WMI isn't complete, yet. Microsoft hasn't provided a WMI "hook" for each thing Windows can do. In fact, the coverage for Windows XP and Windows Server 2003 is light-years better than what's in Windows 2000, and that's better still than NT. But even Windows Server 2003's implementation of WMI doesn't let you query or control the DHCP service, modify IPv6 in any way, modify DNS server records (although you can do that through ADSI in Active Directory-integrated DNS zones), or a hundred other tasks. Eventually, you'll probably be able to do all of those things with WMI, but not today.
|
![]() |
Table of Contents |
![]() |