Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to uniquely identify any storage media connected to a Windows PC in .NET?

I have been searching for a solution to this for weeks. I'm looking for a way I can uniquely identify any storage media connected to a Windows PC. Storage media in particular. This can include internal hard drives, external hard drives, flash drives, SD cards, smartphone storage, etc. No optical media.

Basically what I want to do, is designate some kind of unique string that is tied to a specific storage device, so any time that storage device is reconnected, regardless of drive letter, it can be auto-detected.

Problems I have run into:

  • Not every storage device has a serial number
  • When SD cards are accessed via a card reader, the information available available through WMI via the ManagementObjectSearcher class is related to the card reader rather than the media

It seems there are 4 main properties that CAN return unique information, but don't always. SerialNumber, Caption, PNPDeviceID, Signature

Surely there must be SOMETHING that Windows does to keep track of storage devices like this. Any ideas?

like image 538
cowsay Avatar asked Oct 05 '13 19:10

cowsay


1 Answers

Can you write to these media? If so, how about creating a file in the root directory containing a GUID and storing a reference to that GUID in your app. As GUIDs and guaranteed unique, you can use this file to uniquely identify the volume.

like image 88
David Arno Avatar answered Nov 15 '22 04:11

David Arno