Reputation:
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.
Upvotes: 4
Views: 5522
Reputation: 11
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.
Upvotes: 1
Reputation: 49237
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:
Upvotes: 7