-
January 19th, 2006, 12:09 AM
#1
Get CPU Serial Number
Dear All,
I want to know how we can Get the CPU serial number using C++ code. I found some ASM instruction "cpuid" . But it was not working...
Is there any API for getting CPU informations including CPU Serial Num ber ?. I know some API calls, but there no way to get CPUID from those APIs.
Thanks to all...
Regards,
Ajai
-
January 19th, 2006, 01:13 AM
#2
Re: Get CPU Serial Number
This thread might help you. Someone's posted a zip file which supposedly contains C++ code for obtaining the processor's serial number. I haven't tried it myself though.
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
January 19th, 2006, 02:29 AM
#3
Re: Get CPU Serial Number
-
January 19th, 2006, 04:23 AM
#4
Re: Get CPU Serial Number
try to use WMI classes to retrieve CPU spesific information.
use Win32_Processor class
-
January 19th, 2006, 04:39 AM
#5
Re: Get CPU Serial Number
Making a search for for few magic words you'll find that was asked many, many times...
Well, neither using whatever WMI function nor someting else (like CPUID instruction) can help to get CPU serial number.
THIS THREAD can reveal that for you.
Last edited by ovidiucucu; January 19th, 2006 at 04:42 AM.
-
March 30th, 2006, 10:51 AM
#6
Re: Get CPU Serial Number
I've two identical PC's, I use WMI classes and I obtain the identical information!!
Any idea to obtain different ID ??
These are the classes and objects that I use:
From Win32_BaseBoard: Tag, Manufacturer, Product and Version
From Win32_BIOS: SerialNumber
From Win32_ComputerSystemProduct: IdentifyingNumber and UUID
From Win32_Processor: ProcessorID
And I also use ..Public Declare Function GetVolumeInformation& Lib "kernel32" Alias "GetVolumeInformationA".. from WinAPI32.
My theorical UniqueID is:
InfoBaseBoard & "_" & InfoBIOS & "_" & InfoComputer & "_" & InfoCPU & "_" & InfoDiskDriveC
But, as I say before, I obtain a identical UniqueID with two identical PCs.
------------
Sorry for my English.
-
August 22nd, 2010, 06:18 PM
#7
Re: Get CPU Serial Number
Hello,
I wonder if you could manage to obtain two different identifiers on two machines that are identical. I would need a hint myself.
Thx for the info
br
-
August 23rd, 2010, 02:06 AM
#8
Re: Get CPU Serial Number
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
August 23rd, 2010, 11:18 AM
#9
Re: Get CPU Serial Number
Geez this thread is old.
CPU serial numbers are not unique.
You can use MAC addresses of NIC's installed. Although a user is able to change these values to whatever they want.
You can get the volume serial number of a hard drive. Although I think user's can change this too.
-
October 24th, 2013, 03:14 AM
#10
Re: Get CPU Serial Number
#include <stdio.h>
void getPSN(char *PSN)
{int varEAX, varEBX, varECX, varEDX;
char str[9];
//%eax=1 gives most significant 32 bits in eax
__asm__ __volatile__ ("cpuid": "=a" (varEAX), "=b" (varEBX), "=c" (varECX), "=d" (varEDX) : "a" (1));
sprintf(str, "%08X", varEAX); //i.e. XXXX-XXXX-xxxx-xxxx-xxxx-xxxx
sprintf(PSN, "%C%C%C%C-%C%C%C%C", str[0], str[1], str[2], str[3], str[4], str[5], str[6], str[7]);
//%eax=3 gives least significant 64 bits in edx and ecx [if PN is enabled]
__asm__ __volatile__ ("cpuid": "=a" (varEAX), "=b" (varEBX), "=c" (varECX), "=d" (varEDX) : "a" (3));
sprintf(str, "%08X", varEDX); //i.e. xxxx-xxxx-XXXX-XXXX-xxxx-xxxx
sprintf(PSN, "%s-%C%C%C%C-%C%C%C%C", PSN, str[0], str[1], str[2], str[3], str[4], str[5], str[6], str[7]);
sprintf(str, "%08X", varECX); //i.e. xxxx-xxxx-xxxx-xxxx-XXXX-XXXX
sprintf(PSN, "%s-%C%C%C%C-%C%C%C%C", PSN, str[0], str[1], str[2], str[3], str[4], str[5], str[6], str[7]);
}
int main()
{
char PSN[30]; //24 Hex digits, 5 '-' separators, and a '\0'
getPSN(PSN);
printf("%s\n", PSN); //compare with: lshw | grep serial:
return 0;
}
-
October 24th, 2013, 05:57 AM
#11
Re: Get CPU Serial Number
When posting code, please format properly first and use code tags. Go Advanced, select code and click '#'.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
November 1st, 2013, 03:06 AM
#12
Re: Get CPU Serial Number
amitmishra, thanks for your enthusiasm to help. Keep in mind that this thread has been around for 7 YEARS. There are many current threads that needs help.
I am closing this thread now, because it has been revived in 2010 and now in 2013
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|