Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find USB drive letter?

Tags:

.net

usb

I'm writing a setup program to install an application to a USB drive. The application is meant to be used only from USB drives, so it would save an extra step for the user by automatically selecting USB drive to install to.

I might explore using Nullsoft or MSI for install, but since I'm mostly familiar with .NET I initially plan to try either custom .NET installer or setup component on .NET.

Is it possible to determine the drive letter of a USB flash drive on Windows using .NET? How?

like image 580
Sumrak Avatar asked Sep 23 '08 21:09

Sumrak


1 Answers

You could use:

from driveInfo in DriveInfo.GetDrives()
where driveInfo.DriveType == DriveType.Removable && driveInfo.IsReady
select driveInfo.RootDirectory.FullName
like image 165
Kent Boogaart Avatar answered Oct 31 '22 18:10

Kent Boogaart