Generating a unique machine id
With our licensing tool we consider the following components
- MAC Address
- CPU (Not the serial number, but the actual CPU profile like stepping and model)
- System Drive Serial Number (Not Volume Label)
- Memory
- CD-ROM model & vendor
- Video Card model & vendor
- IDE Controller
- SCSI Controller
However, rather than just hashing the components and creating a pass/fail system, we create a comparable fingerprint that can be used to determine how different two machine profiles are. If the difference rating is above a specified tolerance then ask the user to activate again.
We've found over the last 8 years in use with hundreds of thousands of end-user installs that this combination works well to provide a reliably unique machine id - even for virtual machines and cloned OS installs.
Parse the SMBIOS yourself and hash it to an arbitrary length. See the PDF specification for all SMBIOS structures available.
To query the SMBIOS info from Windows you could use EnumSystemFirmwareEntries
, EnumSystemFirmwareTables
and GetSystemFirmwareTable
.
IIRC, the "unique id" from the CPUID instruction is deprecated from P3 and newer.
I had the same problem and after a little research I decided the best would be to read MachineGuid
in registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography
, as @Agnus suggested. It is generated during OS installation and won't change unless you make another fresh OS install. Depending on the OS version it may contain the network adapter MAC address embedded (plus some other numbers, including random), or a pseudorandom number, the later for newer OS versions (after XP SP2, I believe, but not sure). If it's a pseudorandom theoretically it can be forged - if two machines have the same initial state, including real time clock. In practice, this will be rare, but be aware if you expect it to be a base for security that can be attacked by hardcore hackers.
Of course a registry entry can also be easily changed by anyone to forge a machine GUID, but what I found is that this would disrupt normal operation of so many components of Windows that in most cases no regular user would do it (again, watch out for hardcore hackers).
What about just using the UniqueID of the processor?