Click here to Skip to main content
15,867,939 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I need c++ source code to get CPU number, motherboard number,HDD number
Posted
Comments
barneyman 9-Aug-12 2:42am    
how about you search yourself? (I even used your question title!) - when you've chosen one of the proposed methods, and implemented it, and have problems, THEN come here and ask a question about it?

I won't give you source code, but you can use this information to write the code yourself:

The system information functions are here: http://msdn.microsoft.com/en-us/library/ms724953(VS.85).aspx[^]

For instance, you might be interested in the GetSystemInfo()[^] API, which gives you with a SYSTEM_INFO[^] structure, which will have some of the information you need.
 
Share this answer
 
v2
Comments
Joan M 9-Aug-12 3:11am    
Nice links... 5ed.
Rajesh R Subramanian 9-Aug-12 3:12am    
Hey, thanks. :-)
nilam Kasalkar 9-Aug-12 3:25am    
SYSTEM_INFO function does not have cpu number.
Rajesh R Subramanian 9-Aug-12 3:41am    
The compiler instruction __cpuid can get that: http://msdn.microsoft.com/en-us/library/hskdteyh(v=vs.100).aspx

I feel that answers to your queries can be found with a simple search of the internet. Why not try that?
nilam Kasalkar 9-Aug-12 4:54am    
I write code

int CPUInfo[4] = {-1};
__cpuid(CPUInfo, 1);
if (CPUInfo[0] < 4)
{
CAlert::InformationAlert("Not");
}

stringstream st;
for(int i = 0; i <= 3; i++){
st << CPUInfo[i];
}
string ProcessorSN=st;
But does not give CPU serial number.
Long time since the question was posted but here's some answers if you would be on Linux

motherboard id can be retrieved from: /sys/class/dmi/id/board_serial
cpuinfo from /proc/cpuinfo
hdd info from running the command: /sbin/udevadm info --query=property --name=sda
 
Share this answer
 
//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;
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900