Click here to Skip to main content
15,921,660 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am doing a project in which i have to detect which usb hub is being used by the user and what type of device is being connected, so far I am able to detect the type of device connected but no idea how to detect the usb hub being used, any ideas?
I am using VS 2013 with Win 7 x64.
Posted
Updated 14-Jul-15 19:25pm
v2
Comments
mrDivan 15-Jul-15 3:12am    
You could try the following


public class WinDevices
{
static public List<deviceinfo> GetUSBDevices()
{
List<deviceinfo> devices = new List<deviceinfo>();

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


foreach (var device in collection)
{
var deviceInfo = new DeviceInfo();
deviceInfo.DeviceID = (string)device.GetPropertyValue("DeviceID");
deviceInfo.PNPDeviceID = (string)device.GetPropertyValue("PNPDeviceID");
deviceInfo.Description = (string)device.GetPropertyValue("Description");
deviceInfo.Name = (string)device.GetPropertyValue("Name");
deviceInfo.Caption = (string)device.GetPropertyValue("Caption");
deviceInfo.Service = (string)device.GetPropertyValue("Service");
devices.Add(deviceInfo);

// Other properties supported by Win32_PnPEntity
// See http://msdn.microsoft.com/en-us/library/aa394353%28v=vs.85%29.aspx
//var keys = new string[] {
// "Availability",
// "Caption",
// "ClassGuid",
// "CompatibleID[]",
// "ConfigManagerErrorCode",
// "ConfigManagerUserConfig",
// "CreationClassName",
// "Description",
// "DeviceID",
// "ErrorCleared",
// "ErrorDescription",
// "HardwareID[]",
// "InstallDate",
// "LastErrorCode",
// "Manufacturer",
// "Name",
// "PNPDeviceID",
// "PowerManagementCapabilities[]",
// "PowerManagementSupported",
// "Service",
// "Status",
// "StatusInfo",
// "SystemCreationClassName",
// "SystemName"
//};

}

collection.Dispose();
return devices;
}

public class DeviceInfo
{
public string Name { get; set; }
public string DeviceID { get; set; }
public string PNPDeviceID { get; set; }
public string Description { get; set; }
public string Caption { get; set; }
public string Service { get; set; }
}
}

Kind regards
Divan
Member 11144482 15-Jul-15 5:49am    
hi , your codes is working like a charm , but I am still unable to find out which serial port the device emulates..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900