Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I uniquely identify a USB key from C#?

Tags:

c#

windows

I'd like to be able to detect when a USB key is inserted. Furthermore, if I can distinguish between USB key A and USB key B then I am in even better shape. Lastly, if I can uniquely identify the key using some sort of hardware serial number, MAC address or whatever, then I'm in the best shape of all.

Basically I am looking at using a USB key as a hardware dongle to "unlock" my C# application.

like image 268
Erik Avatar asked Mar 05 '09 05:03

Erik


1 Answers

All hard-drives have a Serial Number, USB flash drives are no different. Here is an article, with a sample project, that shows how to get the non-volatile serial number. Basically you just need to enumerate the system drives and grab the PNPDeviceID property.

like image 147
Beep beep Avatar answered Nov 05 '22 07:11

Beep beep