Click here to Skip to main content
13,559,184 members
Click here to Skip to main content
Add your own
alternative version


28 bookmarked
Posted 14 Oct 2003

Windows Management Instrumentation (WMI) made easy

, 14 Oct 2003
Rate this:
Please Sign up or sign in to vote.
Some easy to use classes to query WMI objects.

Sample Image - testrun.gif


The .NET System.Management namespace is in most cases, not straight forward. If you want to make some quick success in calling WMI from local or remote machines, take a look at this small class library.


To read something about the standards from the DMTF, look here. WMI is an implementation from Microsoft of the CIM standards from the DMTF, the documentation from Microsoft can be found here.

Using the code

If you want to use these classes in your own project, add a reference to the System.Management library and to the class library easywmi.

In your class, add these two using statements.

using System.Management;
using EasyWMI;

Now you can connect to a WMI source, but first you have to set some connection options.

//set connection options
//Connection credentials to the remote computer 
//- not needed if the logged in account has access
ConnectionOptions oConn = new ConnectionOptions();
//oConn.Username = "test";
//oConn.Password = "test";    

//create new WMI manager
CWMIManager wmi = new 
  CWMIManager("localhost", string.Empty, oConn);

With the instance of the CWMIManager class, you can now directly submit WQL-queries.

//execute WQL directly
//get system information
ManagementObjectCollection oCompSys = 
  wmi.ExecWQL("SELECT * FROM Win32_ComputerSystem");
foreach(ManagementObject oReturn in oCompSys) 

Or you can use a specific manager class from the library, when you don't know the WQL-statement.

//use a manager
//create new drive manager
CWMIDriveManager drive = new CWMIDriveManager(wmi);

//get drives
ManagementObjectCollection oDrives = drive.getDrives();
foreach(ManagementObject oDrive in oDrives) 


  • Version 1.0 - 2003-10-15


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Holger Jannasch
Web Developer
Germany Germany
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionTest connection Pin
Radu_2021-Nov-07 5:43
memberRadu_2021-Nov-07 5:43 
GeneralThanks Pin
Venilla8-Feb-07 22:38
memberVenilla8-Feb-07 22:38 
GeneralA good beginning Pin
Michael P Butler19-Oct-03 22:46
memberMichael P Butler19-Oct-03 22:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01-2016 | 2.8.180515.1 | Last Updated 15 Oct 2003
Article Copyright 2003 by Holger Jannasch
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid