delphi 获得cpu硬件信息

解决方案 »

  1.   

    http://www.google.cn/search?hl=zh-CN&client=firefox-a&rls=org.mozilla%3Azh-CN%3Aofficial&hs=sfi&newwindow=1&q=delphi+cpu%E7%A1%AC%E4%BB%B6%E4%BF%A1%E6%81%AF&btnG=Google+%E6%90%9C%E7%B4%A2&aq=f&oq=
      

  2.   

    http://hi.baidu.com/t810509/blog/item/0d8d3d986a66b70f6f068c7f.html
      

  3.   

    //GetIp 
    function   LocalIP   :   string;   
    type   
            TaPInAddr   =   array   [0..10]   of   PInAddr;   
            PaPInAddr   =   ^TaPInAddr;   
    var   
            phe     :   PHostEnt;   
            pptr   :   PaPInAddr;   
            Buffer   :   array   [0..63]   of   char;   
            I         :   Integer;   
            GInitData             :   TWSADATA;   
    begin   
            WSAStartup($101,   GInitData);   
            Result   :=   ``;   
            GetHostName(Buffer,   SizeOf(Buffer));   
            phe   :=GetHostByName(buffer);   
            if   phe   =   nil   then   Exit;   
            pptr   :=   PaPInAddr(Phe^.h_addr_list);   
            I   :=   0;   
            while   pptr^[I]   <>   nil   do   begin   
                result:=StrPas(inet_ntoa(pptr^[I]^));   
                Inc(I);   
            end;   
            WSACleanup;   
    end; function   TCpuInfo.GetCPUID:   string; 
    begin 
    {asm 
        PUSH         EBX                   //Save   affected   register 
        PUSH         EDI 
        MOV           EDI,EAX           //@Resukt 
        MOV           EAX,1 
        DW             $A20F               //CPUID   Command 
        STOSD                               //CPUID[1] 
        MOV           EAX,EBX 
        STOSD                               //CPUID[2] 
        MOV           EAX,ECX 
        STOSD                               //CPUID[3] 
        MOV           EAX,EDX 
        STOSD                               //CPUID[4] 
        POP           EDI                   //Restore   registers 
        POP           EBX 
    end;} 
        Result   :=   IntToHex(FEAXValue,   8)   +   '- '   +   IntToHex(FEBXValue,   8)   +   '- '   +   IntToHex(FECXValue,   8)   +   '- '   +   IntToHex(FEDXValue,   8) 
    end; function   GetCpuId:longint; 
    var 
        temp:longint; 
    begin 
        asm 
            PUSH         EBX 
            PUSH         EDI 
            MOV           EDI,EAX 
            MOV           EAX,1 
            DW             $A20F 
            MOV           TEMP,EDX 
            POP           EDI 
            POP           EBX 
        end; 
        result:=temp; 
    end;
      

  4.   

    WMI也可獲取系統硬件信息uses ActiveX, ComObj;function GetWMIProperty(WMIType, WMIProperty: string): string;
    var
      Wmi, Objs, Obj: OleVariant;
      Enum: IEnumVariant;
      C: Cardinal;
    begin
      Wmi:= CreateOleObject('WbemScripting.SWbemLocator');
      Objs := Wmi.ConnectServer('.','root\cimv2').ExecQuery('Select * from Win32_' + WMIType);
      Enum := IEnumVariant(IUnknown(Objs._NewEnum));
      Enum.Reset;
      Enum.Next(1, Obj, C);
      Obj := Obj.Properties_.Item(WMIProperty, 0).Value;
      Result := Obj;
    end;
     // 獲取硬碟序號
    ShowMessage(GetWMIProperty('DiskDrive', 'PNPDeviceID'));
    // 獲取BISO序號
    ShowMessage(GetWMIProperty('BIOS', 'SerialNumber'));
    // 獲取網卡MAC位址
    ShowMessage(GetWMIProperty('NetworkAdapter', 'MACAddress'));
    // 獲取網卡序號
    ShowMessage(GetWMIProperty('NetworkAdapter', 'PNPDeviceID'));
    // 獲取CPU序號
    ShowMessage(GetWMIProperty('Processor', 'ProcessorId'));也可以用同樣的方法獲得任意感興趣的系統資訊,比如正在運行的進程、帳戶資訊等等。function GetComputerType(TypeValue: integer): string;
    begin
      case TypeValue of
        1: Result := 'Other';
        2: Result := 'Unknown';
        3: Result := 'Desktop';
        4: Result := 'LowProfileDesktop';
        5: Result := 'PizzaBox';
        6: Result := 'MiniTower';
        7: Result := 'Tower';
        8: Result := 'Portable';
        9: Result := 'Laptop';
        10: Result := 'Notebook';
        11: Result := 'Handheld';
        12: Result := 'DockingStation';
        13: Result := 'AllInOne';
        14: Result := 'SubNotebook';
        15: Result := 'SpaceSaving';
        16: Result := 'LunchBox';
        17: Result := 'MainSystemChassis';
        18: Result := 'ExpansionChassis';
        19: Result := 'SubChassis';
        20: Result := 'BusExpansionChassis';
        21: Result := 'PeripheralChassis';
        22: Result := 'StorageChassis';
        23: Result := 'RackMountChassis';
        24: Result := 'SealedCasePC';
      end;
    end;
    procedure TForm4.Button1Click(Sender: TObject);
    var
      s: string;
    begin
      s := GetComputerType(StrToInt(getwmiproperty('SystemEnclosure', 'ChassisTypes')));
      showmessage(s);
    end;