2016-07-07 244 views
0

我试过这段代码,但它只检索“ClassGuid”。有没有办法获得USB设备的接口Guid?如何获得USB设备的接口GUID?

private void loadUsbDevices() 
{ 
    using (var searcher = new ManagementObjectSearcher(
     @"SELECT * FROM Win32_PnPEntity WHERE DeviceID LIKE 'USB%'")) 
    { 
     ManagementObjectCollection collection = searcher.Get(); 

     foreach (var device in collection) 
     { 
      Console.WriteLine(((string) device.GetPropertyValue("Name")) + " (" 
         + ((string) device.GetPropertyValue("ClassGuid")) + ") " 
         + ((string)device.GetPropertyValue("DeviceID"))); 
     } 
    } 
} 
+0

您的设备是否碰巧使用WinUSB作为其驱动程序? –

+0

@DavidGrayson是的 – joyqi

回答

1

由于您的设备使用了WinUSB作为司机,你可能已经安排了一个名为在注册表中该设备被插入DeviceInterfaceGUIDs注册表值。您可以使用SetupDiOpenDevRegKeyRegQueryValueExW检索相同的值。对于这是否一些示例代码,看到这个代码libusbp:

https://github.com/pololu/libusbp/blob/890379c54ef58de46afc60b9c3eccfe2bd66d523/src/windows/generic_interface_windows.c#L93

您也可以在的libusb的源代码中找到相似的代码。