Skip to content

Latest commit

 

History

History
55 lines (42 loc) · 2.11 KB

README.md

File metadata and controls

55 lines (42 loc) · 2.11 KB

EasyWMI

EasyWMI is a C# Class Library that interfaces with Windows Management Instrumentation (WMI). The intended purpose for this class library is to provide an easy method to query WMI via C#.

Supported Alias(es) can be found here:

Easy Syntax

WMIData.cs

The WMIData class is a wrapper for the WMIProcessor class; it gives you a managed use of the WMIProcessor object.

// WMIData object with default request + Extra Request.
WMIData wmiData = new WMIData(true);
wmiData.GetData(WMI_ALIAS.NETWORK_INTERFACE_CARD_CONFIG, "ipaddress");

foreach ( var currentAlias in wmiData.Properties )
{
    Console.WriteLine(currentAlias.Key.Value);
    foreach( var currentProperty in wmiData.Properties[currentAlias.Key] )
    {
        Console.WriteLine("{0} : {1}", currentProperty.Key, currentProperty.Value);
    }
    Console.WriteLine();
}

WMIProcessor.cs

The WMIProcessor class uses a Process object to execute the request.

// Request WMI data from a remote machine.
WMIProcessor wmi = new WMIProcessor();
wmi.Request = WMI_ALIAS.CPU;
wmi.Filter = "name,threadcount,architecture";
wmi.RemoteExecute = true;
wmi.NodeName = "10.1.2.8";
String result = wmi.ExecuteRequest();

// Change RemoteExecute to false. Executes query on local machine.
wmi.RemoteExecute = false;
String result = wmi.ExecuteRequest();

// Shorthand Remote 
WMIProcessor wmi = new WMIProcessor("10.1.2.8", WMI_ALIAS.CPU, "name,threadcount,architecture", true);
String result = wmi.ExecuteRequest();

// Shorthand Local
WMIProcessor wmi = new WMIProcessor(WMI_ALIAS.CPU, "name,threadcount,architecture");
String result = wmi.ExecuteRequest();

Filter is optional for all cases.