开发者

Get USB serial number c++

开发者 https://www.devze.com 2023-01-04 04:41 出处:网络
I\'m looking to retrieve the serial number from a USB memory stick o开发者_如何学编程n windows in c++.

I'm looking to retrieve the serial number from a USB memory stick o开发者_如何学编程n windows in c++.

I have found plenty of C# examples, and c++ for linux but none for c++ and windows.

Edit

  • C++/CLI is not an option unfortunately.
  • I am looking for the serial number of the device not the file system. OR "Device Instance Path" AKA "InstanceID"


I have an article about how to get USB serial numbers for volumes in C++, without using WMI

http://oroboro.com/usb-serial-number/

There is a trick to doing it, you have to match up USB devices with disk volumes. You want to avoid WMI if you can because it is unreliable.


If C++ is a requirement then you'll have to write COM code. A bit unjoyful compared to VB.NET code, but there are very good examples available in the MSDN library, you just need to adapt the query.

Beware that the example you linked to does not return a serial number of the device itself, just the file system on the device. Which is as good as it is going to get it, USB devices don't have serial numbers.

File system serial numbers are trivial to duplicate, in case you are contemplating this to write some kind of licensing enforcement scheme. If that's important then you should use a USB device that was designed for that purpose. A dongle. Impossible to crack. And C++ code to verify the license will be available from the manufacturer.


The serial number is the subkey under HKLM\SYSTEM\CCS\Enum\USB\Vid_xxxx&Pid_yyyy

0

精彩评论

暂无评论...
验证码 换一张
取 消