Click here to Skip to main content
14,102,245 members
Click here to Skip to main content
Add your own
alternative version


179 bookmarked
Posted 24 Jan 2012
Licenced CPOL

Searching for a reliable hardware ID

, 28 Jan 2015
Rate this:
Please Sign up or sign in to vote.
How a computer can be identified in order to generate a unique ID.


Many desktop application developers need to uniquely identify the computer in which their software is running on. 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. 

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 per each machine.

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.


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


About the Author

Michael Haephrati
CEO Secured Globe, Inc.
United States United States
Michael Haephrati, CEO and co-founder of Secured Globe, Inc. Worked on many ventures starting from HarmonySoft, designing Rashumon, the first Graphical Multi-lingual word processor for Amiga computer. During 1995-1996 he worked as a Contractor with Apple at Cupertino.

You may also be interested in...

Comments and Discussions

GeneralMy vote of 1 Pin
JoeDude12328-Mar-16 17:53
memberJoeDude12328-Mar-16 17:53 
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
mvpMichael Haephrati3-Apr-16 9:26 
QuestionWhat about flipAndCodeBytes in ReadPhysicalDriveInNTWithZeroRights? Pin
SkySniper28-Aug-15 3:54
memberSkySniper28-Aug-15 3:54 
AnswerRe: What about flipAndCodeBytes in ReadPhysicalDriveInNTWithZeroRights? Pin
SkySniper28-Aug-15 5:16
memberSkySniper28-Aug-15 5:16 
Questioncan use it for Non-MFC Pin
Member 102071188-Aug-15 11:32
memberMember 102071188-Aug-15 11:32 
AnswerRe: can use it for Non-MFC Pin
Michael Haephrati9-Aug-15 4:30
mvpMichael Haephrati9-Aug-15 4:30 
BugDeviceIoControl Bug Pin
Christoph Derigo19-May-15 8:02
memberChristoph Derigo19-May-15 8:02 
Questionadditional thoughts Pin
Gernot Frisch2-Feb-15 5:32
memberGernot Frisch2-Feb-15 5:32 
AnswerRe: additional thoughts Pin
Michael Haephrati3-Feb-15 10:37
mvpMichael Haephrati3-Feb-15 10:37 
QuestionUnique Machine ID pretty much impossible Pin
Mike Nordell1-Feb-15 12:05
memberMike Nordell1-Feb-15 12:05 
AnswerRe: Unique Machine ID pretty much impossible Pin
Michael Haephrati3-Feb-15 10:38
mvpMichael Haephrati3-Feb-15 10:38 
GeneralRe: Unique Machine ID pretty much impossible Pin
Mike Nordell7-Feb-15 15:11
memberMike Nordell7-Feb-15 15:11 
QuestionWMI? Pin
dandy7228-Jan-15 12:14
memberdandy7228-Jan-15 12:14 
SuggestionIt's risky to be depend on only one id Pin
Cracked-Down28-Jan-15 7:12
memberCracked-Down28-Jan-15 7:12 
GeneralRe: It's risky to be depend on only one id Pin
Michael Haephrati28-Jan-15 7:22
mvpMichael Haephrati28-Jan-15 7:22 
GeneralMy vote of 5 Pin
JunfengGuo7-Jul-14 15:16
memberJunfengGuo7-Jul-14 15:16 
GeneralMy vote of 5 Pin
wangluozhanglei17-Sep-13 23:53
memberwangluozhanglei17-Sep-13 23:53 
GeneralMy vote of 5 Pin
Member 1023960228-Aug-13 22:24
memberMember 1023960228-Aug-13 22:24 
GeneralMy vote of 5 Pin
Oded Sagi15-Aug-13 4:22
memberOded Sagi15-Aug-13 4:22 
GeneralMy vote of 5 Pin
alonamir12-Aug-13 22:00
memberalonamir12-Aug-13 22:00 
GeneralMy vote of 4 Pin
lyyong9-Jul-13 15:25
professionallyyong9-Jul-13 15:25 
GeneralRe: My vote of 4 Pin
Michael Haephrati9-Jul-13 20:06
mvpMichael Haephrati9-Jul-13 20:06 
GeneralMy vote of 5 Pin
alonbarak14-Jun-13 11:11
groupalonbarak14-Jun-13 11:11 
QuestionCurrent drive insteat of main drive Pin
Karsten Gutjahr4-Mar-13 2:30
memberKarsten Gutjahr4-Mar-13 2:30 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.190518.1 | Last Updated 28 Jan 2015
Article Copyright 2012 by Michael Haephrati
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid