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.!!

