WMI查询PNP_entity的父级/子级

10

我正在开发一个使用C#编写的程序,用于检测USB设备是否在特定的USB集线器上被检测到。我知道集线器和连接到集线器上的从设备的PID和VID。 我通过使用ManagementObjectSearcher查询来获取设备信息:

ManagementObjectSearcher USBSearchQuery = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_PnPEntity WHERE DeviceID LIKE \"%VID_17EF&PID_6019%\"");
ManagementObjectCollection DeviceCollection = USBSearchQuery.Get();

这很好用。ManagementObjectCollection DeviceCollection包含2个元素。一个是HID设备,另一个是USB设备。当我检查设备管理器时,可以看到这些元素并访问Parent属性,但似乎不可能通过WMI查询获取对象的父级或子级。

我可以通过集线器的子级或设备的父级来实现这一点。你们有没有想法如何做到这一点?


我知道这是很久以前的事情了,但你最终找到解决方案了吗?我也有完全相同的用例! - Gilles jr Bisson
2个回答

0
ManagementObjectCollection DeviceCollection = USBSearchQuery .Get();
foreach (ManagementObject mo in DeviceCollection )
    {
      //get all properties 
      //ex: mo.Properties["Description"].Value represents the friendly name of the device
      //mo.Properties["PNPClass"].Value represents the parent class of the device
    }

问题是关于父设备(按连接)而不是父类的。 - Mr. TA


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接