Programming with Windows Management Instrumentation
- Programming with Windows Management Instrumentation
- WMI Overview
- Implementing WMI
- Calling the Component
- Adding Some Extras
Dan Fox walks you through a simple development project that shows you the capabilities of Windows Management Instrumentation (WMI).
Although it hasn't been focused on as often as other technologies have, Microsoft has included a gem in Windows 2000 that finally makes it easy to gather configuration information programmatically from one or more computers. This revolution—which goes by the handle WMI—consists of a standard API that exposes a myriad of settings that are accessible from any automation-capable client, such as VB, VBA, and ASP. While you may have had some inkling about the capabilities of WMI, it may not be entirely clear how you as a VB developer can take advantage of this technology. So, before you hit the back button on your browser because you consider WMI to be for system administrators and other network geeks only, let me show you a simple solution that utilizes VB and WMI in a real development project.
WBEM to the Rescue
Before we get to WMI, we need to briefly review its ancestry. Microsoft developed WMI as the implementation of an industry initiative known as Web-Based Enterprise Management (WBEM). The purpose of this initiative was to create a single set of Internet-based standards for managing devices and systems on an enterprise network in order to supplant technologies such as Simple Network Management Protocol (SNMP) and Desktop Management Interface (DMI). The WBEM initiative is now in the hands of the Distributed Management Task Force (DMTF). (For more information on DMTF, see www.dmtf.org/wbem.)
WBEM is comprised of several technologies, the most important being CIM (Common Information Model). CIM is an object-oriented data model that is made up of instances, methods, and properties; this technology is used to describe management information in an enterprise network. The specification is implementation and vendor-neutral, and is expressed through Managed Object Format (MOF) files. MOF files are text files that contain the definition of classes or actual object instances that represent aspects of an enterprise network. For example, the DMTF has defined five common schemas for systems, applications, databases, networks, and devices. The schemas contain classes (all prefixed with CIM—such as CIM_NetworkAdapter— in order to indicate that they are standard) that represent devices, as shown here:
class CIM_NetworkAdapter : CIM_LogicalDevice { [MaxLen (64), Description ( "PermanentAddress defines the network address hardcoded into " "an adapter. This 'hardcoded' address may be changed via " "firmware upgrade or software configuration. If so, this field " "should be updated when the change is made. PermanentAddress " "should be left blank if no 'hardcoded' address exists for the " "NetworkAdapter."), ] string PermanentAddress; [MaxLen (64), Description ( "An array of strings indicating the network addresses for an " "adapter."), ArrayType ("Indexed") ] string NetworkAddresses[]; [Description ( "An estimate of the current bandwidth in Bits per Second. " "For Adapters which vary in bandwidth or for those where " "no accurate estimation can be made, this property should " "contain the nominal bandwidth."), Units ("Bits per Second") ] uint64 Speed; [Description ( "The maximum speed, in Bits per Second, for the Network" "Adapter."), Units ("Bits per Second") ] uint64 MaxSpeed; [Description ( "Boolean indicating that the Adapter is operating in " "full duplex mode.") ] boolean FullDuplex; [Description ( "A boolean indicating whether the Network Adapter is capable " "of automatically determining the speed or other communications " "characteristics of the attached network media.") ] boolean AutoSense; [Description ( "The total number of octets transmitted, including framing " "characters."), Counter ] uint64 OctetsTransmitted; [Description ( "The total number of octets received, including framing " "characters."), Counter ] uint64 OctetsReceived; };
In this case, the CIM_NetworkAdapter class inherits from CIM_LogicalDevice and contains properties of the adapter. In addition, vendors can inherit from these classes and extend them if their particular hardware or software supports features that are not present in the standard classes. For example, Microsoft extends many of the standard classes by prefixing the class name with "Win32"—the Microsoft class for network adapters is then called Win32_NetworkAdapter. For more information on CIM schemas, see www.dmtf.org/spec/cim_schema_v23.htm.
CIM schemas define the standard set of data, but not the implementation. As a result, it's up to hardware and software vendors to implement these standards. That's where WMI comes in.