C# class to generate an Unique Hardware ID.
Sometimes is required create unique identifiers for PCs. There are different approaches for doing that, the most basic among these is to use hardware IDs since they're constant (at most of time).
The most popular are the First Drive Volume ID and the processor ID, using the Windows Management Instrumentation (WMI) infrastructure.
This simple class (about 8kb) generates two unique IDs.
- SimpleUID, a concatenation of the First Drive Volume ID and the processor ID.
- AdvancedUID, the simpleUID plus a MD5 hash of the Windows build version.
- In Virtualized environments (eg. VirtualBox, VMware, etc) the processor is not available through the WMI. Thus, the class implements an inline Assembly solution (credits to: http://stackoverflow.com/questions/16460485/inline-assembly-code-to-get-cpu-id).
- The MD5 hash is generated using the Windows codename and the build number in order to avoid repetition when the build number is the same for 2 or more different operating systems. E.g. Windows 7 & Windows Server 2008 had the same build number. You can check out an approximate list of the Windows Version Numbers on http://www.gaijin.at/en/lstwinver.php.
- The project files and the solution files were intentionally made in Visual C# 2010 Express for convenience of users, and targets to .NET Framework 2.0 x86 with compatibility purposes.
- DO NOT use any of the generated UIDs for production environments, since the code is public, anyone can replicate the UID. It's STRONGLY RECOMMENDED to scramble/encrypt the generated UID with a application specific algorithm.
- AVOID use external libraries (like this) to generate & validate licenses, due to anybody could patch the dll file to break your licensing system.
- Source: https://github.com/davcs86/csharp-uhwid
- Bugs: https://github.com/davcs86/csharp-uhwid/issues
- .NET Framework 2.0+
- Visual C# 2010 Express (and later).
-
As zip from this repository: https://github.com/davcs86/csharp-uhwid/archive/master.zip
-
With git from a terminal:
git clone https://github.com/davcs86/csharp-uhwid.git
-
a) Compile the downloaded code and reference the DLL in your project, or
-
b) Add the file /UHWID/UHWID.cs to your project.
-
Add the namespace UHWID where you'll use the class.
using UHWID;
-
Get any of the UIDs
String SimpleUID = UHWIDEngine.SimpleUID; String AdvancedUID = UHWIDEngine.AdvancedUID;
Drop me line on: [email protected]
Did this project help you to save (or earn) some money?
Please, support to the author by making a small donation.