Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
Can anyone please tell me how get processor serial number(psn) using _cpuid() function i tried lot but i cant get. Please help me
Posted 9-Aug-12 0:05am
Comments
Volynsky Alex at 10-Aug-12 5:42am
   
Please see following links:
http://www.codeproject.com/Articles/6359/Get-the-PIII-processor-serial-number-psn-in-Intel
http://stackoverflow.com/questions/5658975/c-get-processor-id
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
nilam Kasalkar at 9-Aug-12 6:31am
   
It return true or false for processor serial number.
I write code
int info[4] = { -1 };
 
__cpuid(info, 0);
if (info[0] < 1)
{
CAlert::InformationAlert("Not");
}
 
// Up to you...you do not need to mask results and you may use
// features bits "as is".
__cpuid(info, 1);
int family = info[0] & 0xf00;
int features = info[3] & 0xf000;
 
std::stringstream id;
id << std::hex << std::setw(4) << std::setfill('0') << family << features;
 
But i dont get
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

public string GetCPUId()
	{
	    string cpuInfo =  String.Empty;        
	    //create an instance of the Managemnet class with the
	    //Win32_Processor class
	    ManagementClass mgmt = new ManagementClass("Win32_Processor");
	    //create a ManagementObjectCollection to loop through
	    ManagementObjectCollection objCol = mgmt.GetInstances();
	    //start our loop for all processors found
	    foreach(ManagementObject obj in objCol)
	    {
	        if(cpuInfo == String.Empty)
	        {
            // only return cpuInfo from first CPU
	            cpuInfo = obj.Properties["ProcessorId"].Value.ToString();
	        }           
	    }
	    return cpuInfo;    
	}
    }
 
this program may help you to get processorID.
  Permalink  
Comments
nilam Kasalkar at 16-Aug-12 4:56am
   
How to do this in MAC OS?
Please help.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

try to use WMI classes to retrieve CPU spesific information.
use Win32_Processor class .
  Permalink  
Comments
nilam Kasalkar at 9-Aug-12 6:54am
   
How to use Win32_Processor class in c++ to retrieve cpu number
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Usually is invoked in the C program a function with asm code. Some ideas you can found in Wikipedia CPUID. In linux there are two options: dmidecode and libcpuid.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Get the MAC (Media Access Control) address. But this may not be more interesting than the CPU ID.
 
- Get the name of the computer with:
Code:
 
int get_computer_name(BYTE *computer_name, DWORD *computer_name_lg)
{
   HKEY hKey;
   if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
               "SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ComputerName",
               0, KEY_QUERY_VALUE, &hKey ) != ERROR_SUCCESS)
      return FALSE;
   if (RegQueryValueEx(hKey, "ComputerName", NULL, NULL,
                       (LPBYTE) computer_name,
                       (LPDWORD) computer_name_lg) != ERROR_SUCCESS) {
      RegCloseKey(hKey);
      return FALSE;
   }
   RegCloseKey(hKey);
   return TRUE;
}
...
   BYTE name[250] = "Default name";
   DWORD name_lg = 250;
   if (get_computer_name(name, &name_lg) == TRUE) {
   ...
   }
This is working well with my Windows ME computer and with my Windows XP computer. But, unfortunately there is no guarantee that computer names will be unique. It depends on the name that was assigned to them when Windows was installed.
  Permalink  
v2
Comments
nilam Kasalkar at 9-Aug-12 7:24am
   
I need unique machine id
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

#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;
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 9

using System;
using System.Windows.Forms;
using System.Management;
5namespace trainingCSharp
{
public partial class Form1 : Form
{
public Form1()
1 {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_Processor");
string info = "";
foreach (ManagementObject obj in searcher.Get())
{
try
{
info = obj.Properties["ProcessorId"].Value.ToString() + "\n";
}
catch { }
}
MessageBox.Show(info);
}

}
}
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 575
1 George Jonsson 285
2 Garth J Lancaster 280
3 Sergey Alexandrovich Kryukov 264
4 Maciej Los 250
0 Sergey Alexandrovich Kryukov 10,879
1 OriginalGriff 5,555
2 Maciej Los 5,534
3 CPallini 3,819
4 BillWoodruff 3,594


Advertise | Privacy | Mobile
Web02 | 2.8.141030.1 | Last Updated 4 Nov 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100