joyqi
joyqi

Reputation: 123

How to get the interface guid of USB device?

I have tried this code, but it only retrieves the "ClassGuid". Is there a way to get the USB device's Interface 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")));
        }
    }
}

Upvotes: 1

Views: 3680

Answers (1)

David Grayson
David Grayson

Reputation: 87531

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. You can retrieve that same value using SetupDiOpenDevRegKey and RegQueryValueExW. For some example code that does this, see this code from libusbp:

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.

Upvotes: 1

Related Questions