1. 程式人生 > >怎麼獲取CPU序列號

怎麼獲取CPU序列號

void CCPU_SerialNumberDlg::OnButton1() 
{
// TODO: Add your control notification handler code here
unsigned long s1,s2;
unsigned char vendor_id[]="------------";
char sel;
sel='1';
CString VernderID;
CString MyCpuID,CPUID1,CPUID2;
switch(sel)
{
case '1':
__asm{
xor eax,eax
cpuid
mov dword ptr vendor_id,ebx
mov dword ptr vendor_id[+4],edx
mov dword ptr vendor_id[+8],ecx
}
VernderID.Format("%s-",vendor_id);
__asm{
mov eax,01h
xor edx,edx
cpuid
mov s1,edx
mov s2,eax
}
CPUID1.Format("%08X%08X",s1,s2);
__asm{
mov eax,03h
xor ecx,ecx
xor edx,edx
cpuid
mov s1,edx
mov s2,ecx
}
CPUID2.Format("%08X%08X",s1,s2);
break;
case '2':
{
__asm{
mov ecx,119h
rdmsr
or eax,00200000h
wrmsr
}
}
printf("CPU id is disabled.\n");
break;
}
MyCpuID = CPUID1+CPUID2;
AfxMessageBox(MyCpuID);
}
僅僅intel的cpu有序列號,AMD的沒有,所以上面程式碼僅適用intel