How to get the CPU Name String?

21 06 2009


While taking the System properties, you have noticed the processor name string. For instance, in my laptop it is – “Intel(R) Core(TM)2 Duo CPU     T5250  @ 1.50GHz“. Ever though about how to get this processor name string?

cpuid
Image Courtesy – Wallpaper Mania.


You can use the function – __cpuid(), which generates the instruction – cpuid. Have a look at the code snippet. Code taken and modified from MSDN.

#include <iostream>
#include <intrin.h>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    // Get extended ids.
    int CPUInfo[4] = {-1};
    __cpuid(CPUInfo, 0x80000000);
    unsigned int nExIds = CPUInfo[0];

    // Get the information associated with each extended ID.
    char CPUBrandString[0x40] = { 0 };
    for( unsigned int i=0x80000000; i<=nExIds; ++i)
    {
        __cpuid(CPUInfo, i);

        // Interpret CPU brand string and cache information.
        if  (i == 0x80000002)
        {
            memcpy( CPUBrandString,
            CPUInfo,
            sizeof(CPUInfo));
        }
        else if( i == 0x80000003 )
        {
            memcpy( CPUBrandString + 16,
            CPUInfo,
            sizeof(CPUInfo));
        }
        else if( i == 0x80000004 )
        {
            memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo));
        }
}

    cout << "Cpu String: " << CPUBrandString;
}


You can get a lot of information about cpu by using __cpuid. Have a look at the MSDN Documentation.


Targeted Audiance – Intermeidate.