Reputation: 13828
How do I get the PnpDevice Id of a specific device? for a webcam or soundcard? The below code gets me PNPIds of all devices but I'm unable to identify which id is for what device.
using System;
using System.Management;
using System.Windows.Forms;
namespace WMISample
{
public class MyWMIQuery
{
public static void Main()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\WMI",
"SELECT * FROM MSWmi_PnPDeviceId");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("MSWmi_PnPDeviceId instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Active: {0}", queryObj["Active"]);
Console.WriteLine("InstanceName: {0}", queryObj["InstanceName"]);
Console.WriteLine("PnPDeviceId: {0}", queryObj["PnPDeviceId"]);
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
}
}
}
}
Upvotes: 1
Views: 1232
Reputation: 7812
PnPDeviceId which you will get from instance of MSWmi_PnPDeviceId can be used to query Win32_PnPEntity (namespace ROOT\CIMV2) class instances to get more details of device. e.g. SELECT * FROM Win32_PnPEntity WHERE DeviceID=PnPDeviceId
Win32_PnPEntity class has around 26 properties which will give more details of device.
PFB one such screenshot.
Upvotes: 1