WMI centralises the management of Windows servers and workstations into a common object-based infrastructure. By standardising functionality, additional management functions can be introduced into the WMI framework with great simplicity. As new functionality is introduced into later releases of the Windows operating system, providers are implemented to manage the new functions. Providers act as the interface between a computer resource (such as a disk drive or partition) and other WMI components handling the interaction with resources, to ensure that a standard interface is available through WMI. Windows Management Instrumentation isn't just for storage; it allows you to monitor and manage almost every aspect of your computer setup. You can find a list of the standard providers at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_providers.asp New providers have been introduced with Windows 2003 Server. For example, the Shadow Copy Provider is new with this operating system. So, let's get coding and see what we can do. Below is a script to display basic information on your local PC. Copy the data into a file with the extension *.vbs.
strComputer = "." strOutput = ""
So how does this work? Well, line 3 of the code connects to the WMI service. The local computer is displayed as ".", but you can specify any remote computer to which you have access. Line 4 requests details on all objects of the class type "Win32_DiskDrive" on this machine. Lines 6 to 8 loop through each of the returned objects (each one representing a physical disk) and displays 2 properties, the "Name" and "Size". We then repeat this process, this time using the class "Win32_DiskPartition". As you can see, from a simple piece of code we can easily determine disk information on any computer we can access. The command standards in the format of the class objects makes it easier to re-use our existing code. There are dozens of classes that provide information on your computer and are logically grouped into namespaces. The classes used in this article are part of the root\CIMV2 namespace. Others include root\directory\ldap, which maps out Active Directory information and root\default, which provides access to the registry. A great way to see all of the available classes and their properties is to download the "WMI Object Browser", part of WMI Tools. You can find the download at: http://msdn.microsoft.com/library/default.asp?url=/downloads/list/wmi.asp Once installed, open up "WMI Object Browser" from the menu. Accept the default namespace of root\CIMV2 and click "OK" to log in as your current logged in user. You can then expand the left-hand frame and locate the disk information under "Win32_SystemDevices". The right-hand pane will display details on the object you choose. Browse around and see what information is available. In the next article, we will look further at WMI. We'll also look at putting the storage information to practical use on a webpage and at what values can be modified.