Many USB devices contain a unique serial number (which is actually a Unicode string) that the host can use in conjunction with 16-bit product and product identifiers to uniquely identify the device.
I am trying to figure out how to write a Windows application that can display a list of all the USB interfaces connected to the system. The list will have one line for each HID, including system keyboards. The list will include columns for vendor ID, product ID, and serial number.
I can get a list of USB HIDs by calling SetupDiGetClassDevswith the GUID returned HidD_GetHidGuidand looping through the result by retyping SetupDiEnumDeviceInterfaces. Then I can call SetupDiGetDeviceInterfaceDetailto get the path to each device that I can open with CreateFile, until I request either read permission or write permission to be rejected for the system keyboard. From there, I can get the product and product identifiers by calling HidD_GetAttributes.
I am having trouble figuring out how to get a serial number string. When I look for solutions to this problem, I find a lot of information on how to get serial numbers for USB mass storage devices, but it does not look like this can apply to any other USB device. I would be happy to discover either a generic method or a HID method to get a serial number string.
I have a feeling that the Win32 port for libusbcan handle this without any problems, but, unfortunately, I need a solution that depends only on the libraries that come with Windows, such as DLLs setupapiand hidwhich contain the functions mentioned above.
Any suggestions would be much appreciated!
source
share