Win32_PnPDevice, ROOT\cimv2, c# samples

Class | Methods | Properties (2) | Qualifiers (6) | Instances (40) | Namespaces (2)
Samples: VB Script | C# | VB.Net | Search on:Microsoft

Win32_PnPDevice - c# code samples

WMI query - sample windows WQL with C#, SameElement property of Win32_PnPDevice

Get a specified instance of Win32_PnPDevice 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.
	//Project -> Add reference -> System.Management
	//using System.Management;
	//create a management scope object
	ManagementScope scope = new ManagementScope("\\\\.\\ROOT\\cimv2");
	//create object query
	ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_PnPDevice Where SameElement=\"\\\\\\\\W2012SDC\\\\ROOT\\\\cimv2:Win32_1394Controller.DeviceID=\\\"PCI\\\\\\\\VEN_104C&DEV_8024&SUBSYS_10001458&REV_00\\\\\\\\4&C9A676E&0&70A4\\\"\"SystemElement=\"\\\\\\\\W2012SDC\\\\root\\\\cimv2:Win32_PnPEntity.DeviceID=\\\"PCI\\\\\\\\VEN_104C&DEV_8024&SUBSYS_10001458&REV_00\\\\\\\\4&C9A676E&0&70A4\\\"\"");
	//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("SameElement : {0}", m["SameElement"]);

WMI query - list of class instances

List of all instances of Win32_PnPDevice class in C#.
See in another language: VBScript, VB.Net.
	//Project -> Add reference -> System.Management
	//using System.Management;
	//set the class name and namespace
	string NamespacePath = "\\\\.\\ROOT\\cimv2";
	string ClassName = "Win32_PnPDevice";
	//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("SameElement : {0}", oObject["SameElement"]);
comments powered by Disqus