问题
How to detect the USB drive letter from c# program which is not residing in the USB? The program should reside in the system, if multiple USB's are connected then i should first able to get the manufacturer name also.
回答1:
This will get all of the removable drives attached (including USB drives):
foreach (DriveInfo drive in DriveInfo.GetDrives())
{
if (drive.DriveType == DriveType.Removable)
{
// Code here
}
}
Getting the USB drive manufacturer may be more difficult, and you may need to use WMI.
Edit: Here are 2 links on reading USB drive information:
- how to determine USB Flash drive manufacturer?
- Finding serial number of USB drive without WMI
回答2:
List<string> list_usb= DriveInfo.GetDrives().Where(d => d.DriveType.ToString() == "Removable").Select(d => d.Name).ToList();
foreach(var i in list_usb)
{
Console.WriteLine(i);
}
you can try this.
来源:https://stackoverflow.com/questions/1273872/how-do-i-detect-a-usb-drive-letter-from-a-c-sharp-application