2

I am looking for a way in C# to have a persistent (across when end-users unplug a hub/restart their computer) identifier for USB slots, more specifically, SD card readers. Drive letters are not always assigned to the same slot, but I need a way to identify Slot A physically; as once I can identify it, I can make the connections to a drive letter.

So my question(s):

  1. Is this possible?
  2. If so, how would I go about getting these identifiers?

1 Answers1

1

WMI class Win32_USBHub.

ManagementObjectSearcher sidQuery = new ManagementObjectSearcher("Select * From Win32_USBHub");
ManagementObjectCollection results = sidQuery.Get();
List<String> deviceID = new List<String>();
foreach (ManagementObject result in results)
{
   deviceID.Add(result["DeviceID"]);
}

See more here : Get List of connected USB Devices

Documentation about Win32_USBHub : http://msdn.microsoft.com/en-us/library/windows/desktop/aa394506(v=vs.85).aspx

Community
  • 1
  • 1
TheMightyX2Y
  • 1,473
  • 1
  • 16
  • 24
  • Thanks! One more question, is there a way to find out if Windows has assigned the USB device any letters (assuming the device is a drive and not a keyboard for instance) and if so, what they are/it is? – user2588050 Aug 01 '13 at 15:20
  • Nevermind, I found the solution to the comment question. [link](http://stackoverflow.com/questions/9467506/how-to-have-the-drive-letter-with-the-device-id-on-windows7) – user2588050 Aug 01 '13 at 16:02