Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am Developing an application where I need to fetch VID and PID of all the Current USB Devices Connected to the Computer.

But I am just getting VID and PID number of my Headphone that is attached to my Computer. and not getting for Mouse and Keyboard.

My Code works like this:-

static List<USBDeviceInfo> GetUSBDevices()
    {
        List<USBDeviceInfo> devices = new List<USBDeviceInfo>();

        ManagementObjectCollection collection;
        using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_USBHub"))
            collection = searcher.Get();

        foreach (var device in collection)
        {
            devices.Add(new USBDeviceInfo(
            (string)device.GetPropertyValue("DeviceID"),
            (string)device.GetPropertyValue("PNPDeviceID"),
            (string)device.GetPropertyValue("Description")
            ));
        }

        collection.Dispose();
        return devices;
    }

Main Class

static void Main(string[] args)
    {
       var usbDevices = GetUSBDevices();
       foreach (var usbDevice in usbDevices)
       {
        Console.WriteLine("Device ID: {0}, PNP Device ID: {1}, Description: {2}",
         usbDevice.DeviceID, usbDevice.PnpDeviceID, usbDevice.Description);
       }
      Console.Read();
     }

Now in case of Headphone I am getting Description as USB Composite Device while in Case of other Devices connected to Computer I am getting Description as USB Root Hub

I don't know why I am getting only VID and PID of only Headphone

Please suggest

Thanks in advance.!!

share|improve this question

closed as off topic by Canadian Luke, BBlake, Kez, Indrek, 8088 Sep 18 '12 at 15:53

Questions on Super User are expected to relate to computer software or computer hardware within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
There is no need to show your code (this site is not a programming site) as it's relevant to your question per se. –  Dave Sep 18 '12 at 11:56

2 Answers 2

up vote 1 down vote accepted

A hub is a device that other devices are connected to. Root hubs represent the USB controllers on your motherboard.

A composite device is a device that has multiple interfaces; your headphones has two interfaces, for mixer controls and for audio capture.

Normal USB devices are not listed as Win32_USBHub, you have too look into the Dependent entries. See Getting the USB Devices Information using WMI for an example.

share|improve this answer
    
Thanks. That is what I was looking for. –  Rahul Sep 18 '12 at 13:05

I'm not covering the coding part of this question - its OT for SU. I can't code anyway

The real issue is, you might be looking at the wrong place

First, go look at device manager.

Here's mine. I've darkened out the less interesting bits and pointed out the useful stuff enter image description here

My gaming mouse is a USB composite device - it consists of two virtual devices (which in this case of what I am assuming is a USB headset. Else it wouldn't appear at all). Hence it appears in 3 places - under HID, under Keyboards and under Mice and other pointing devices amd as a USB controller.

My keyboard ONLY appears under HID and Keyboards since its a boring, non sexy piece of logitech gear. It SHOULD NOT turn up under USB controllers.

In short? You may relook your code, and learn a little about how windows classifies hardware.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.