Home > Uncategorized > C# Code: Querying WMI and Executing a WMI Method

C# Code: Querying WMI and Executing a WMI Method

Executing a WMI query:

ManagementObjectSearcher searcher = new
ManagementObjectSearcher("select * from CIM_DesktopMonitor");
foreach (ManagementObject service in searcher.Get())
{
MessageBox.Show(" " + service["Availability"]);
}

Executing a WMI method:

/* Using SetPowerState Method of the CIM_DesktopMonitor Class
* methodArgs = (int PowerState, datetime Time)
* for usable property values refer to http://msdn2.microsoft.com/en-us/library/aa393490(VS.85).aspx
* 
*/
ManagementClass myCompSys = new
ManagementClass("CIM_DesktopMonitor"); //CIM_DesktopMonitor, CIM_FlatPanel
object[] methodArgs = {4,DateTime.Now}; //PowerState = 4, Time = Now
object Result = myCompSys.InvokeMethod("SetPowerState", methodArgs); //this method isn't implemented, aka this doesn't work
MessageBox.Show(" ", Result);
Advertisements
Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: