tags:

views:

794

answers:

2

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.

A: 

You need to retrieve the key's Hardware ID.

I don't see how to subscribe to the plugged-in event, but you could always have the user click a button too.

tsilb
I believe the volumeserialnumber is changed each time the USB drive is formatted by Windows. There is a separate serial number that is non-volatile and probably is better to use.
Jess
+6  A: 

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.

Jess
Thanks, worked perfectly for getting the serial. I don't suppose I could get "lucky" twice and learn about a way to get an event notification when a drive is added to the system?
Erik
Actually here's a related question that looks like what I am looking for: <a href="http://stackoverflow.com/questions/271907/how-to-detect-using-c-if-a-pendrive-is-plugged-into-a-usb-port">click<a/>
Erik