Using WMI From Managed Code

Introduction

This article was originally published on DNJ Online
DNJ Online

Windows Management Instrumentation (WMI) is Microsoft’s implementation of Web-Based Enterprise Management (WBEM), which is the industry standard for unifying the management of distributed computer systems. The WBEM standard includes the Common Information Model (CIM) for describing management information relevant to systems, applications, networks, devices and services. It also defines mechanisms for automating administrative tasks.

WMI can be accessed from C or C++, from Visual Basic, or from any scripting language that has an engine on Windows and is able to handle ActiveX objects. It comes pre-installed on Windows Server 2003, Windows XP, Windows Me and Windows 2000, and can be installed separately on Windows NT or Windows 9x systems.

WMI Architecture

The purpose of WMI is to present a uniform interface to any local or remote applications or scripts that need to access management data from a computer system, network or application. Thanks to WMI, programs do not have to talk to a wide variety of operating system APIs which can be particularly inconvenient for scripting languages.

All WMI interfaces are based on the Component Object Model (COM), however it is possible to access WMI from .NET thanks to the COM Inter-Op mechanism, as our diagram shows.

The main parts of WMI are as follows:

Managed objects and providers: A WMI provider is a COM object that monitors one or more managed objects for WMI. Like a driver, a provider extracts WMI data from a managed object and is responsible for passing messages from WMI back to the managed object. Managed objects can be logical or physical components such as a hard drive, a network adapter, a database system, the operating system itself, a process or an application. An example of a provider is the Win32 provider that handles classes like Win32_Printer, which we’ll use in the sample below.

WMI infrastructure: As a Windows component WMI consists of the Windows Management service, which includes the WMI Core, and the WMI repository. The service acts as an intermediary between the providers and the repository. Only static data about objects, such as the classes defined by the providers, are stored in the repository. Most provider classes are defined in Managed Object Format (MOF) files and then compiled into the WMI repository. The provider also has a DLL file which contains the code needed to implement the classes.

Management applications and scripts: A management application queries management information either by calling the COM API for WMI or through the Scripting API for WMI. Through these, management applications can call methods that instruct or reconfigure a managed object. However the only data or actions available for a managed object are those that a provider supplies.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“If Java had true garbage collection, most programs would delete themselves upon execution.” - Robert Sewell