Enumerate System Devices

Enumerate system devices using C#. You have to add a reference to the System.Management component.

ManagementObjectSearcher devices = new ManagementObjectSearcher("Select Name, Description, Status from Win32_PnPEntity");
 
if (devices != null)
	foreach (ManagementObject device in devices.Get())
	{
		Console.WriteLine("> Device name: {0} Device Desc: {1} Device Status: {2}.rn",
			device.GetPropertyValue("Name").ToString(),
			device.GetPropertyValue("Description").ToString(),
			device.GetPropertyValue("Status").ToString());
	}

For more.. visit microsoft web site.

Categories: C# Tags: , , ,
%d bloggers like this: