连接的USB设备的分类

时间:2015-06-24 19:09:20

标签: winforms winapi c#-4.0 usb systems-programming

我正在编写一个C#应用程序,用于监视和记录连接到Windows系统的不同USB设备。使用Window的设置API,我可以获得诸如VID,PID,硬件ID和友好名称等详细信息。我想问的是Windows中是否有办法检查连接的设备是SmartPhone,打印机,大容量存储设备还是调制解调器?

注意:使用SetupGerDeviceRegistryProperty()我可以获取设备描述,但是对于所有设备,它显示设备描述是USB复合设备。

1 个答案:

答案 0 :(得分:1)

You can use SetupDiGetDeviceRegistryProperty with the SPDRP_SERVICE argument to get the name of the driver installed for the device node. The name of the driver usually indicates what type of device is connected, as long as it is using a standard driver that is part of Windows. You could also use look at the SPDRP_COMPATIBLEIDS, which are the IDs that are used to select those standard drivers. Actually SPDRP_CLASS and SPDRP_CLASSGUID might be the best ones; I think one of those corresponds to the category that the device is displayed under in the Device Manager. It sounds like your devices are composite devices though, so you will need to access the children of the composite device instead of the composite device itself. One way to do that is to call SetupDiGetClassDevs(NULL, "USB", NULL, 0), which will return a device information set that has all the USB devices and all of their children.