Click here to Skip to main content
15,876,991 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I identify a physical USB drive uniquely in .Net C# code, so as to distinguish it from any other USB drive, even one with the same file structure on it? I do not mean the port, but the actual device called a thumb drive.

What I have tried:

The System.Management namespace used to have a useful object in it, but it is no longer available.
Posted
Updated 1-Mar-20 4:23am

The System.Management namespace is still there. There haven't really been any changes to the code in there in a long time, so I don't know what you mean by "used to".

But, that namespace in the .NET Framework doesn't have any impact on the classes available in WMI, which usually start with the name "Win32_".

If you have code that uses System.Management that used to work and now doesn't, you haven't explained any problem with it, nor shown the code that no longer works, so there's really nothing we can do about that.


Now, if you are trying to use a USB drive as a "security key", you can't. There is nothing about these drives that is absolutely unique from one drive to the next. You can't even assume there is a serial number exposed by the devices.
 
Share this answer
 
v2
 
Share this answer
 
Try this:
C#
var drives = DriveInfo.GetDrives().Where(
                    drive => drive.IsReady && drive.DriveType == DriveType.Removable);

                if (drives.Count() > 0)                
                {
                    List<DriveNameInfo> driveNameInfo = new List<DriveNameInfo>();
                    foreach (DriveInfo driveInfo in drives)
                        driveNameInfo.Add(new DriveNameInfo(driveInfo.Name,               driveInfo.VolumeLabel));
}
 
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