GetSystemInfomation只能得到架构,我想获得象
Intel Pentium 4 CPU 2.4G这样的信息,该怎么做呢?

解决方案 »

  1.   

    可通过查询注册表得到。HKEY hKey;
    RegOpenKeyEx( HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &hKey);
    char strName[50];
    unsigned long length = sizeof(strName);
    DWORD type_1=REG_SZ;
    RegQueryValueEx( hKey, "ProcessorNameString", NULL, &type_1, (unsigned char *)strName, &length );
    RegCloseKey(hKey);
      

  2.   

    // 获得处理器频率
    #include < iostream >
    using namespace std;
    #include < windows.h >unsigned __int64 GetCPUSpeed(){
        unsigned __int64 start, stop;
        unsigned __int64 nCtr, nFreq, nCtrStop; 
        QueryPerformanceFrequency((LARGE_INTEGER *)&nFreq);
        _asm _emit 0x0F
        _asm _emit 0x31
        _asm mov DWORD PTR start, eax
        _asm mov DWORD PTR [start+4], edx
        QueryPerformanceCounter((LARGE_INTEGER *)&nCtrStop);
        nCtrStop += nFreq;
        do{
            QueryPerformanceCounter((LARGE_INTEGER *)&nCtr);
        } while (nCtr < nCtrStop);
        _asm _emit 0x0F
        _asm _emit 0x31
        _asm mov DWORD PTR stop, eax
        _asm mov DWORD PTR [stop+4], edx
        return (stop-start);
    }int main()
    {
    char szRet[256];
    __int64 tmp;
    SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
        SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
    cout << "Please wait..." << endl;
    tmp = GetCPUSpeed();
    sprintf(szRet,"%I64u",tmp);
        cout << szRet << endl;
    return 0;
    }// 获得 CPU 类型,用VC, console
    #include < iostream >
    using namespace std;unsigned int SteppingID;
    unsigned int Model;
    unsigned int Family;
    unsigned int ProcessorType;
    unsigned char Brand;
    unsigned long VersionInfo;
    unsigned long FeatureInfo;template < typename T >
    void Print(char* a,T ret){
      cout << a << ":\t"<< ret << endl;
    }void PrintBrand(char* str){
      cout << "This processor is:" << str << endl;
    }void GetFeature(long i,char *str)
    {   
      _asm xor ebx,ebx
      _asm mov ebx,i
      _asm bt FeatureInfo,ebx //"bt" is opcode to test a particular bit(on/off) in a string
                  //The bit number to test is provided as the second operand
                  //The result is stored in the carry flag
      _asm jnc Feature_not_installed
      cout << "CPU Feature: " << str << "\tO" << endl;
      return;
      Feature_not_installed:
      cout << "CPU Feature: " << str << "\tX" << endl;
    }
    int main()
    {
    char *strFeatures[32]={
        "FPU    ",// x87 FPU on Chip
        "VME    ",// Virtual 8086 Enhancement
        "DE     ",// Debugging Extensions
        "PSE    ",// Page Size Extensions
        "TSC    ",// Time Stamp Counter
        "MSR    ",// RDMSR and WRMSR Support
        "PAE    ",// Physical Address Extensions
        "MCE    ",// Machine Check Exception
        "CX8    ",// CMPXCHG8B instruction
        "APIC   ",// Advanced Programmable Interrupt Controller on Chip
        " ",   //Reserved     10
        "SEP    ",// SYSENTER and SYSEXIT
        "MTRR   ",// Memory Type Range Register
        "PGE    ",// PTE Global Bit
        "MCA    ",// Machine Check Architecture
        "CMOV   ",// Condtional Move/Compare Instruction
        "PAT    ",// Page Attribute Table
        "PSE-32 ",// Page Size Extension
        "PSN    ",// Processor Serial Number
        "CLFSH  ",// CFLUSH Instruction
        " ",   //Reserved   20
        "DS     ",// Debug Store
        "ACPI   ",// Thermal Monitor and Clock Control
        "MMX    ",// MMX Technology
        "FXSR   ",// FXSAVE/FXRSTOR
        "SSE    ",// SSE Extensions
        "SSE2   ",// SSE2 Extensions
        "SS     ",// Self Snoop
        "HTT    ",// Hyper Threading Tech
        "TM     ",//Thermal Monitor
        " ",   //Reserved       30
        "PBE    ",// Pend. Brk. En
    };char* strProcessorType[]={
      "ProcessorType", "Original OEM Processor",
      "ProcessorType", "Intel OverDrive Processor",
      "ProcessorType", "Dual Processor",
      "ProcessorType", "Intel reserved"
    };char* strComputerBrand[]={
    "This Processor does not support the brand identification feature",
    "Intel Celeron",
    "Intel Pentium III",
    "Intel Pentium III Xeon or Intel Celeron",
    "Intel Pentium III",
        "Mobile Intel Pentium III-M",
    "Other Processor",
    "Mobile Intel Celeron",
    "Intel Pentium 4",
    "Intel Pentium 4",
    "Intel Celeron",
    "Intel Xeon or Xeon MP",
    "Intel Xeon MP",
    "Mobile Intel Pentium 4  or Intel Xeon",
    "Other Processor",
    "Other Processor",
    "Other Processor",
    "Other Processor",
    "Other Processor",
    "Other Processor",
    "Mobile Intel Celeron",
    "Mobile Intel Celeron",
    "Intel Pentium M"
    };char VendorID[13];
    _asm
    {
      mov eax,0
      cpuid // CPUID Instruction
      mov dword ptr [VendorID],ebx
      mov dword ptr [VendorID+4],edx
      mov dword ptr [VendorID+8],ecx
      mov byte ptr [VendorID+12],0
    }// Show the Vendor ID. Should be "GenuineIntel" if the processor is Intel"/////////////
       cout << "Processor Vendor: " << VendorID << endl;
    //Store all the required information in memory////////////////////////////////////////
    _asm
    {
      mov eax,1
      cpuid               //CPUID Instruction
      mov VersionInfo,eax //Store Version Information
      mov FeatureInfo,edx //Store Feature Information
      mov Brand,bl        //Store Brand Information
    }
    //Extract the SteppingID, model and family from the bit encoded VersionInfo and display
    SteppingID = VersionInfo & 0x0F;            //Stepping ID
    Model = (VersionInfo & 0xF0)>> 4;           //Model
    Family = (VersionInfo & 0x0F00) >> 8;       //Family
    ProcessorType = (VersionInfo & 3000) >> 12; //Processor TypePrint("SteppingID", SteppingID);
    Print("Model", Model);
    Print("Family", Family);
    //Show the Processor Type
    Print("The Processor Type is",strProcessorType[ProcessorType]);//Show the Computer Brand
    if(Brand <= 22)
      Print("This processor is",strComputerBrand[Brand]);
    else
      Print("This processor is","Other Processor");//Get Processor features
    for(int i=0 ; i < 32; i++)
    {
      GetFeature(i,strFeatures[i]);
    }
      return 0;
    }