c#.NET USB device persistent identifier

纵饮孤独 提交于 2019-12-24 01:50:55

问题


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:


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



来源:https://stackoverflow.com/questions/17997284/c-net-usb-device-persistent-identifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!