TheSwamp

Code Red => .NET => Topic started by: k005 on November 19, 2021, 02:19:43 PM

Title: How can I find the usb drive letter c#
Post by: k005 on November 19, 2021, 02:19:43 PM
Hello guys;

There is an xxx.exe file on the drive. How can I find the drive letter on which drive this file is located? can you help?

Thanks.
Title: Re: How can I find the usb drive letter c#
Post by: n.yuan on November 20, 2021, 09:34:34 AM
Obviously, you need search all the drives of the file system of your computer, if you do not know which drive the file would be, regardless it being USB (removable) drive or not.

You can use the static method of System.IO.DriveInfo.GetDrives() to get a list of all available drives, and search each of them until you find the file. With DriveInfo class, you can tell what type of the drive is (fixed. removable, network...).
Title: Re: How can I find the usb drive letter c#
Post by: k005 on November 21, 2021, 07:30:20 AM
Hi.,


I know which drive the file is on.

on a flash disk.

My goal is to do some sort of license protection. That's why I asked.

let's say ; There is abcd.exe file in G: drive.

What should be the code that gives me the drive letter of this? so how can i get G?