windows 如何从 C# 中唯一标识 USB 密钥?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/613634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I uniquely identify a USB key from C#?
提问by Erik
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.
我希望能够检测到何时插入了 USB 密钥。此外,如果我能区分 USB Key A 和 USB Key B,那么我的状态会更好。最后,如果我可以使用某种硬件序列号、MAC 地址或其他任何东西来唯一地识别密钥,那么我就处于最佳状态。
Basically I am looking at using a USB key as a hardware dongle to "unlock" my C# application.
基本上,我正在考虑使用 USB 密钥作为硬件加密狗来“解锁”我的 C# 应用程序。
回答by Beep beep
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.
所有硬盘驱动器都有序列号,USB 闪存驱动器也不例外。这是一篇带有示例项目的文章,展示了如何获取非易失性序列号。基本上,您只需要枚举系统驱动器并获取 PNPDeviceID 属性。
回答by tsilb
You need to retrieve the key's Hardware ID.
您需要检索密钥的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.
我不知道如何订阅插件事件,但您也可以始终让用户单击按钮。
回答by Muris
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.
硬盘 ID 不是唯一的。也许理论上是这样,但实际上并非如此。这是没有任何破解,模拟器或任何特殊程序。