5

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.

Erik
  • 304
  • 2
  • 5
  • 10

3 Answers3

8

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.

Beep beep
  • 18,873
  • 12
  • 63
  • 78
  • 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 Mar 05 '09 at 06:45
  • Actually here's a related question that looks like what I am looking for: click – Erik Mar 05 '09 at 15:41
0

Hard Disk Id is not unique. Maybe theoretically it is, but in practice it is not. This is without any crack, emulator or any special program.

Muris
  • 158
  • 8
0

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
  • 7,977
  • 13
  • 71
  • 98
  • 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. – Beep beep Mar 05 '09 at 05:25