5

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.

Evan Carslake
  • 2,267
  • 15
  • 38
  • 56
sidd607
  • 1,339
  • 2
  • 18
  • 29
  • Perhaps "Device Categories" ? – Harry Johnston Jun 24 '15 at 21:18
  • In Device Manager, one of the properties is "Device Categories". That might contain the information you want - at least, it lists my cellphone as a phone. I'm not sure what that translates to in terms of the API but it shouldn't be too hard to find out - but check in Device Manager first to see whether or not that information is actually useful for you. – Harry Johnston Jun 25 '15 at 00:33
  • yeah it does.. But I wanted a solution where I can get that classification programatically – sidd607 Jun 25 '15 at 17:38
  • Everything you can get from Device Manager you can get from the API. At a guess you want [DEVPKEY_DeviceDisplay_Category](https://msdn.microsoft.com/en-us/library/windows/hardware/ff542348(v=vs.85).aspx). – Harry Johnston Jun 25 '15 at 21:51

1 Answers1

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.

David Grayson
  • 84,103
  • 24
  • 152
  • 189
  • Thanks for accepting my answer. To help future readers, could you say which registry properties you ended up using? My answer mentioned four different ones. – David Grayson Jul 01 '15 at 16:14