Click here to Skip to main content
15,867,488 members
Articles / Programming Languages / C++

Searching for a Reliable Hardware ID

Rate me:
Please Sign up or sign in to vote.
4.93/5 (106 votes)
26 Mar 2020CPOL3 min read 282.8K   17.7K   212   143
How a computer can be identified in order to generate a unique ID
Many desktop application developers need to uniquely identify the computer on which their software is running. This article will show you how it can be done.

Introduction

Many desktop application developers need to uniquely identify the computer on which their software is running. Such identification must produce a unique data element which will be different per each computer and will reproduce the same ID on any given computer.  Note: there is also an excellent article focusing on the BIOS UUID. The article was written by .

The WMI Set of Classes 

Windows provides a set of classes that can be used for most hardware enumeration and identification tasks, which is named WMI or Windows Management Instrumentation. These are extensions to the Windows Driver Model (WDM).

WMI provides per instrumented component static information and dynamic notification about any changes. Most programming languages can be used to manage, locally and remotely, computers and servers, enumerating their instrumented components and alerted for changes that occur.

During my research, I came to the conclusion that if speed and reliability is important, it is better to access hardware via the Win32 API and not use WMI. I have experienced many delays and in some occasions, WMI failed to detect an element such as the CPU ID.

This article focuses on the direct approach for obtaining this data without using WMI.

Obtaining a Unique CPU ID

The solution that seems to be the best choice is to sample the CPU unique identification number (or CPU ID). However, there are several problems that makes it impossible to rely on reading the CPU ID.

To begin with, most CPUs with the exception of the old Pentium III, don't have a unique CPU Serial Number. Intel has removed this feature for privacy reasons.

It is still possible to generate a unique ID from the motherboard as a whole. That certainly works but the huge number of different types of motherboards and manufacturers makes it next to impossible to generate a unique ID that will cover all of them.

In fact, a French company named CPU ID, focuses in this field and spends a lot of resources in getting to learn each type of motherboard and CPU, in order to cover them all.

The following screenshot shows the details that can be collected for each machine.

Image 1

Their SDK can be downloaded here, and can be used both as a static library (per special request) or a DLL with any application developed. The bad news is that even the guys from CPUID say it is impossible to generate a unique hardware ID based on the CPU or the motherboard of a given machine.

MAC Address Based Hardware ID

The next choice for obtaining such a unique ID would be sampling the MAC address. To begin with, what is the "MAC address"? It stands for Media Access Control. The MAC address is 48 bits long (6 bytes). The GetMACAddress code sample explains how to obtain the MAC address.

However, there is one problem with this approach: the MAC address can be easily changed into a new one...

Hard Drive Serial Number

It seems that the only reliable solution for obtaining a machine ID would be using the serial number of the main Hard Drive. The second example, GetHDSerialNumber, shows how to obtain this ID. From my experience, this approach is the best one and the most reliable for generating a unique machine based hardware ID.

I would like to add that the serial number to be used, must be the one set by the manufacturer as opposed to the one set (and which can be changed) by the Operating System.

History

  • 28th January, 2015: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO Secured Globe, Inc.
United States United States
Michael Haephrati is a music composer, an inventor and an expert specializes in software development and information security, who has built a unique perspective which combines technology and the end user experience. He is the author of a the book Learning C++ , which teaches C++ 20, and was published in August 2022.

He is the CEO of Secured Globe, Inc., and also active at Stack Overflow.

Read our Corporate blog or read my Personal blog.





Comments and Discussions

 
Questionhow to use these unique IDs to protect my software application? Pin
Southmountain5-Oct-20 7:40
Southmountain5-Oct-20 7:40 
Questionunique id really difficult Pin
Jan Heckman27-Mar-20 4:39
professionalJan Heckman27-Mar-20 4:39 
QuestionAlternative: File or registry key Pin
Gernot Frisch27-Mar-20 2:03
Gernot Frisch27-Mar-20 2:03 
AnswerRe: Alternative: File or registry key Pin
Michael Haephrati27-Mar-20 2:53
professionalMichael Haephrati27-Mar-20 2:53 
GeneralMy vote of 5 Pin
Member 1370414327-Mar-20 1:35
Member 1370414327-Mar-20 1:35 
Thank you !
GeneralRe: My vote of 5 Pin
Michael Haephrati27-Mar-20 2:54
professionalMichael Haephrati27-Mar-20 2:54 
PraiseMy vote of 5 Pin
Jim Forst26-Mar-20 22:26
Jim Forst26-Mar-20 22:26 
GeneralRe: My vote of 5 Pin
Michael Haephrati26-Mar-20 23:06
professionalMichael Haephrati26-Mar-20 23:06 
QuestionMy Vote of 5 ... Pin
User 1106097926-Mar-20 12:17
User 1106097926-Mar-20 12:17 
AnswerRe: My Vote of 5 ... Pin
Michael Haephrati26-Mar-20 13:30
professionalMichael Haephrati26-Mar-20 13:30 
GeneralRe: My Vote of 5 ... Pin
User 1106097926-Mar-20 14:01
User 1106097926-Mar-20 14:01 
GeneralRe: My Vote of 5 ... Pin
Michael Haephrati26-Mar-20 15:19
professionalMichael Haephrati26-Mar-20 15:19 
GeneralRe: My Vote of 5 ... Pin
Nelek26-Mar-20 15:52
protectorNelek26-Mar-20 15:52 
GeneralMy vote of 5 Pin
Ștefan-Mihai MOGA26-Mar-20 9:11
professionalȘtefan-Mihai MOGA26-Mar-20 9:11 
GeneralMy vote of 1 Pin
JoeDude12328-Mar-16 17:53
JoeDude12328-Mar-16 17:53 
AnswerRe: My vote of 1 Pin
Michael Haephrati26-Mar-20 13:33
professionalMichael Haephrati26-Mar-20 13:33 
GeneralRe: My vote of 1 Pin
User 1106097926-Mar-20 14:14
User 1106097926-Mar-20 14:14 
GeneralRe: My vote of 1 Pin
Michael Haephrati26-Mar-20 15:21
professionalMichael Haephrati26-Mar-20 15:21 
GeneralMy vote of 5 Pin
csharpbd23-Mar-16 7:56
professionalcsharpbd23-Mar-16 7:56 
GeneralRe: My vote of 5 Pin
Michael Haephrati3-Apr-16 9:26
professionalMichael Haephrati3-Apr-16 9:26 
QuestionWhat about flipAndCodeBytes in ReadPhysicalDriveInNTWithZeroRights? Pin
SkySniper28-Aug-15 3:54
SkySniper28-Aug-15 3:54 
AnswerRe: What about flipAndCodeBytes in ReadPhysicalDriveInNTWithZeroRights? Pin
SkySniper28-Aug-15 5:16
SkySniper28-Aug-15 5:16 
Questioncan use it for Non-MFC Pin
Member 102071188-Aug-15 11:32
Member 102071188-Aug-15 11:32 
AnswerRe: can use it for Non-MFC Pin
Michael Haephrati9-Aug-15 4:30
professionalMichael Haephrati9-Aug-15 4:30 
BugDeviceIoControl Bug Pin
Christoph Derigo19-May-15 8:02
Christoph Derigo19-May-15 8:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.