I am writing a C# application that monitors and logs the different USB devices that are being connected to a windows system. Using Window's setup API, I am able to get the details such as VID, PID, Hardware Id and Friendly name. What I wanted to ask is is there a way in Windows to check is the connected device is a SmartPhone, or a Printer, or a Mass Storage device, or a Modem?
Note: Using SetupGerDeviceRegistryProperty()
I am able to get the Device Description but for all devices it shows that the Device Description is USB Composite Device.
You can use
SetupDiGetDeviceRegistryProperty
with theSPDRP_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 theSPDRP_COMPATIBLEIDS
, which are the IDs that are used to select those standard drivers. ActuallySPDRP_CLASS
andSPDRP_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.