I have been able to enumerate USB devices using the SetupAPI, and I've looked at the usbview application from the WDK, but I still can't figure out how to get the USB_DEVICE_DESCRIPTOR.
- I would rather avoid using WMI.
- DeviceIoControl is what the sample app usbview uses, but that really only works if you're enumerating devices on a Hub. I suppose if I can get to the parent hub (and port) given a device path (or Id), this method may work but I haven't been able to determine how to do this either.
- I have a mix of devices for which I'd like to get the descriptor. Some of these are HIDs, and it's possible some are WinUsb.sys devices. If they are WinUsb devices I can use WinUsb_GetDescriptor, but that won't work for HIDs (and I don't know how to tell the difference between them from the Id or Path...Interface class I guess?).
- I could use SetupDiGetDeviceRegistryProperty but in the list of available properties, I can see the Manufacturer string, but not the vendor Id.
- I could possibly parse this value from the device path or the device Id, but that seems sort of...hack-ish. Is that just what people do though? Also it still leaves me going to other methods if I want other fields like the Manufacturer, where if I could just get the whole USB_DEVICE_DESCRIPTOR I think I'd have about everything I need.
- LibUsb.Net only supports WinUsb devices apparently. That's how it seems to get the descriptor.
- Apparently WinRT has some new APIs and therefore Windows Store apps have a nice way of getting the descriptor. But this is definitely not a Windows Store app, and I don't know that there is another way to use the newer APIs.
Can anyone point me in the right direction? Is it just not possible to get this information from the WinAPI in a nice way without starting at the Hub?
SetupDiGetDeviceProperty
withDEVPKEY_Device_Address
– Ben VoigtCM_Get_DevNode_Property
. Once you have the port number, withCM_Get_Parent
you can get the parent USB hub, open it, send it the IOCTL requesting more information on that port's enumerated device. – Ben Voigt