Reputation: 123
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
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:
You can also find similar code in the source code of libusb.
Upvotes: 1