简体   繁体   English

如何获得USB设备的接口指南?

[英]How to get the interface guid of USB device?

I have tried this code, but it only retrieves the "ClassGuid". 我已经尝试过此代码,但是只能检索“ ClassGuid”。 Is there a way to get the USB device's Interface Guid? 有没有办法获取USB设备的接口向导?

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")));
        }
    }
}

Since your device uses WinUSB as the driver, you have probably already arranged for a registry value named DeviceInterfaceGUIDs to be inserted in the registry for that device. 由于您的设备使用WinUSB作为驱动程序,因此您可能已经安排了一个名为DeviceInterfaceGUIDs的注册表值插入该设备的注册表中。 You can retrieve that same value using SetupDiOpenDevRegKey and RegQueryValueExW . 您可以使用SetupDiOpenDevRegKeyRegQueryValueExW检索相同的值。 For some example code that does this, see this code from libusbp: 有关执行此操作的示例代码,请参见libusbp的以下代码:

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

You can also find similar code in the source code of libusb. 您也可以在libusb的源代码中找到类似的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM