How to get the Device ID of PCI devices?
c#, device, pci, wmi
Solution
According to MSDN, Win32_PhysicalMedia represents any type of documentation or storage medium. If you want to get DeviceID from PCI device (like as in Device Manager at Control Panel) - you need Win32_PnPEntity class, which represents the properties of a Plug and Play device. So, try to use this code:
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_PnPEntity");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("DeviceID: {0}", queryObj["DeviceID"]);
Console.WriteLine("Description: {0}", queryObj["Description"]);
}
Running this code provides me lots of info about my PCI devices
Problem
I am trying to get the system device IDs from the device manager, in C#. I found some code to find the USB device ID, but I don't know how to change the code from USB device to PCI device. This is the code that I found: ``` ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM Win32_SystemDevices WHERE InterfaceType='USB'"); foreach (ManagementObject mo in mos.Get()) { ManagementObject query = new ManagementObject("Win32_PhysicalMedia.Tag='" + mo["DeviceID"] + "'"); Console.WriteLine(query["SerialNumber"]); } ```