CIM_PowerSupply, ROOT\CIMV2\power, c# samples

Class | Childs (1) | Methods (8) | Properties (50) | Qualifiers (4) | Instances (1) | Namespaces (4)
Samples: VB Script | C# | VB.Net | Search on:Microsoft

CIM_PowerSupply - c# code samples

WMI query - sample windows WQL with C#, ActiveInputVoltage property of CIM_PowerSupply

Get a specified instance of CIM_PowerSupply by a key, get a default unnamed instance (singleton) of the class or list instances of the class by wmi query using this c# sample code.
See in another language: VBScript, VB.Net.
	//https://wutils.com/wmi/
	
	//Project -> Add reference -> System.Management
	//using System.Management;
	
	//create a management scope object
	ManagementScope scope = new ManagementScope("\\\\.\\ROOT\\CIMV2\\power");
	
	//create object query
	ObjectQuery query = new ObjectQuery("SELECT * FROM CIM_PowerSupply Where CreationClassName=\"{E39B8438-EA34-47E1-AE39-3BBF5A0FE901}\"DeviceID=\"Power Supply 0\"SystemCreationClassName=\"{D654E2BA-F5EB-40F3-9968-5EA769F31308}\"SystemName=\"{10955413-D51B-4DA0-A6BA-FD5E7251A04B}\"");
	
	//create object searcher
	ManagementObjectSearcher searcher =
	                        new ManagementObjectSearcher(scope, query);
	
	//get a collection of WMI objects
	ManagementObjectCollection queryCollection = searcher.Get();
	
	//enumerate the collection.
	foreach (ManagementObject m in queryCollection) 
	{
	  // access properties of the WMI object
	  Console.WriteLine("ActiveInputVoltage : {0}", m["ActiveInputVoltage"]);
	  
	}
	

WMI query - list of class instances

List of all instances of CIM_PowerSupply class in C#.
See in another language: VBScript, VB.Net.
	//https://wutils.com/wmi/
	
	//Project -> Add reference -> System.Management
	//using System.Management;
	
	//set the class name and namespace
	string NamespacePath = "\\\\.\\ROOT\\CIMV2\\power";
	string ClassName = "CIM_PowerSupply";
	
	//Create ManagementClass
	ManagementClass oClass = new ManagementClass(NamespacePath + ":" + ClassName);
	
	//Get all instances of the class and enumerate them
	foreach (ManagementObject oObject in oClass.GetInstances())
	{
		//access a property of the Management object
		Console.WriteLine("ActiveInputVoltage : {0}", oObject["ActiveInputVoltage"]);
	}
	
comments powered by Disqus
WUtils.com