Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Having problems with doing a program that will detect if the are flash drives on a computer, please help!!
Posted

For example, you can list the removable drives:

C#
using System.IO;

//...

DriveInfo[] drives = DriveInfo.GetDrives();

foreach (DriveInfo drive in drives) {
    if (drive.DriveType == DriveType.Removable)
         // do something...
}


Or, with LINQ:
C#
using System.IO;
using System.Linq;

DriveInfo[] removableDrives =
    DriveInfo.GetDrives().Where(drive => drive.DriveType == DriveType.Removable).ToArray();


To best of my knowledge, there is no a way to tell the flash drive from other removable drive. In a way, this is not really needed. In practice, you only may need to check if the access is read-only or you may to make sure the drive is not the system drive of a currently running OS (because you can always boot from a removable drive).

—SA
 
Share this answer
 
v2
Comments
Sandeep Mewara 18-Jun-12 3:12am    
My 5!
Sergey Alexandrovich Kryukov 18-Jun-12 11:20am    
Thank you, Sandeep.
--SA
It would be a completely different story if you wanted to handle the event when the removable drive is inserted. This is the way you can do it with USB removable storage:

http://stackoverflow.com/questions/271238/how-do-i-detect-when-a-removable-disk-is-inserted-using-c[^].

Unfortunately, this does not exhaust all possibilities. For example, the removable storage could be motherboard-integrated, which is often the case with SD/SDHC/SDXC drives. Such events are detected, but unfortunately, I don't know how to do it, at the moment.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900