win32_USBDevice is missging from Win32 Classes

2019-08-20 03:40发布

I am trying to retrieve PID and VID of a connected USB device. Starting with this line of C# code:

System.Management.ManagementClass USBClass = new ManagementClass("Win32_USBDevice");

Then I got exception "ManagementException not found", Later I run into this link: http://msdn.microsoft.com/en-us/library/windows/desktop/aa394084(v=vs.85).aspx

It turned out Win32_USBDevice was not on the list at all. Tried Win32_USBController but didn't get what I wanted. Could anyone let me know if there is any substitute class on the list to extract PID and VID of a connected USB device?

Thanks in advance!

2条回答
来,给爷笑一个
2楼-- · 2019-08-20 04:23

Use Win32_PnPEntity. You can get the both the PID and VID of connected USB devices from Win32_PnPEntity by parsing the "PNPDeviceID".

Start with this example: Get List of connected USB Devices

查看更多
一纸荒年 Trace。
3楼-- · 2019-08-20 04:34

Try this:

System.Management.ManagementClass USBClass = new ManagementClass("Win32_USBHub");

查看更多
登录 后发表回答