Get CPU Serial Number
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: Get CPU Serial Number

  1. #1
    Join Date
    Jan 2006
    Posts
    16

    Question 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
    Share on Google+

  2. #2
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,239

    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
    Share on Google+

  3. #3
    Join Date
    Jun 2005
    Posts
    1,255

    Smile Re: Get CPU Serial Number

    This other thread might help you:
    http://www.codeguru.com/forum/showthread.php?t=355953
    Share on Google+

  4. #4
    Join Date
    Sep 2005
    Posts
    173

    Re: Get CPU Serial Number

    try to use WMI classes to retrieve CPU spesific information.
    use Win32_Processor class
    Share on Google+

  5. #5
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    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 03:42 AM.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/
    Share on Google+

  6. #6
    Join Date
    Mar 2006
    Posts
    1

    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.
    Share on Google+

  7. #7
    Join Date
    Jun 2007
    Posts
    2

    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
    Share on Google+

  8. #8
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,239

    Re: Get CPU Serial Number

    "A problem well stated is a problem half solved. - Charles F. Kettering
    Share on Google+

  9. #9
    Join Date
    Jun 2009
    Location
    oklahoma
    Posts
    199

    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.
    Share on Google+

  10. #10
    Join Date
    Oct 2013
    Posts
    1

    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;
    }
    Share on Google+

  11. #11
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,335

    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. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
    Share on Google+

  12. #12
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,091

    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
    Share on Google+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center