//intel网站上有该指令的技术文档
procedure GetCpuInfo;
var R: array[0..19] of Char;
var CpuID: Integer;
begin
  FillChar(R, 20, 0);
  asm
    mov eax, 0
    db 0fh, 0a2h               // 其实就是cpuid汇编指令
    mov dword ptr R[0],  ebx
    mov dword ptr R[4],  edx
    mov dword ptr R[8],  ecx
    mov eax, 1
    db 0fh, 0a2h               // cpuid
    mov CpuID, edx
  end;
  ShowMessage('CPU制造商为:' + R);
  ShowMessage('序列号为:' + IntToStr(CpuID));
end;

解决方案 »

  1.   

    ////////////////////////////cpuid.dpr:
    program CpuId;uses
      Forms,
      Main in 'Main.pas' {DemoForm};{$R *.RES}begin
      Application.Initialize;
      Application.CreateForm(TDemoForm, DemoForm);
      Application.Run;
    end.
    ////////////////////////////main.pas
    unit Main;
    interfaceuses
      Windows,
      Messages,
      SysUtils,
      Classes,
      Graphics,
      Controls,
      Forms,
      Dialogs,
      ExtCtrls,
      StdCtrls,
      Buttons;type
      TDemoForm = class(TForm)
        Label1: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        Label4: TLabel;
        GetButton: TBitBtn;
        CloseButton: TBitBtn;
        Bevel1: TBevel;
        Label5: TLabel;
        FLabel: TLabel;
        MLabel: TLabel;
        PLabel: TLabel;
        SLabel: TLabel;
        PValue: TLabel;
        FValue: TLabel;
        MValue: TLabel;
        SValue: TLabel;
        procedure GetButtonClick(Sender: TObject);
      end;var
      DemoForm: TDemoForm;implementation{$R *.DFM}const
    ID_BIT = $200000; // EFLAGS ID bit
    type
    TCPUID = array[1..4] of Longint;
    TVendor = array [0..11] of char;function IsCPUID_Available : Boolean; register;
    asm
    PUSHFD {direct access to flags no possible, only via stack}
      POP     EAX {flags to EAX}
      MOV     EDX,EAX {save current flags}
      XOR     EAX,ID_BIT {not ID bit}
      PUSH    EAX {onto stack}
      POPFD {from stack to flags, with not ID bit}
      PUSHFD {back to stack}
      POP     EAX {get back to EAX}
      XOR     EAX,EDX {check if ID bit affected}
      JZ      @exit {no, CPUID not availavle}
      MOV     AL,True {Result=True}
    @exit:
    end;function GetCPUID : TCPUID; assembler; register;
    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;function GetCPUVendor : TVendor; assembler; register;
    asm
      PUSH    EBX {Save affected register}
      PUSH    EDI
      MOV     EDI,EAX {@Result (TVendor)}
      MOV     EAX,0
      DW      $A20F {CPUID Command}
      MOV     EAX,EBX
      XCHG EBX,ECX     {save ECX result}
      MOV ECX,4
    @1:
      STOSB
      SHR     EAX,8
      LOOP    @1
      MOV     EAX,EDX
      MOV ECX,4
    @2:
      STOSB
      SHR     EAX,8
      LOOP    @2
      MOV     EAX,EBX
      MOV ECX,4
    @3:
      STOSB
      SHR     EAX,8
      LOOP    @3
      POP     EDI {Restore registers}
      POP     EBX
    end;procedure TDemoForm.GetButtonClick(Sender: TObject);
    var
      CPUID : TCPUID;
      I     : Integer;
      S : TVendor;
    begin
    for I := Low(CPUID) to High(CPUID)  do CPUID[I] := -1;
      if IsCPUID_Available then begin
      CPUID := GetCPUID;
      Label1.Caption := 'CPUID[1] = ' + IntToHex(CPUID[1],8);
       Label2.Caption := 'CPUID[2] = ' + IntToHex(CPUID[2],8);
      Label3.Caption := 'CPUID[3] = ' + IntToHex(CPUID[3],8);
       Label4.Caption := 'CPUID[4] = ' + IntToHex(CPUID[4],8);
       PValue.Caption := IntToStr(CPUID[1] shr 12 and 3);
      FValue.Caption := IntToStr(CPUID[1] shr 8 and $f);
       MValue.Caption := IntToStr(CPUID[1] shr 4 and $f);
      SValue.Caption := IntToStr(CPUID[1] and $f);
      S := GetCPUVendor;
       Label5.Caption := 'Vendor: ' + S; end
      else begin
       Label5.Caption := 'CPUID not available';
      end;
    end;end.
    ///////////////////////main.dfm:
    object DemoForm: TDemoForm
      Left = 392
      Top = 259
      Width = 312
      Height = 222
      ActiveControl = GetButton
      BorderIcons = [biSystemMenu]
      Caption = 'CPUID - DemoForm'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      OldCreateOrder = True
      Position = poScreenCenter
      PixelsPerInch = 96
      TextHeight = 13
      object Bevel1: TBevel
        Left = 8
        Top = 8
        Width = 289
        Height = 137
      end
      object Label1: TLabel
        Left = 24
        Top = 24
        Width = 125
        Height = 13
        Caption = 'CPUID[1] = FFFFFFFF'
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clWindowText
        Font.Height = -11
        Font.Name = 'MS Sans Serif'
        Font.Style = [fsBold]
        ParentFont = False
      end
      object Label2: TLabel
        Left = 24
        Top = 48
        Width = 125
        Height = 13
        Caption = 'CPUID[2] = FFFFFFFF'
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clWindowText
        Font.Height = -11
        Font.Name = 'MS Sans Serif'
        Font.Style = [fsBold]
        ParentFont = False
      end
      object Label3: TLabel
        Left = 24
        Top = 72
        Width = 125
        Height = 13
        Caption = 'CPUID[3] = FFFFFFFF'
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clWindowText
        Font.Height = -11
        Font.Name = 'MS Sans Serif'
        Font.Style = [fsBold]
        ParentFont = False
      end
      object Label4: TLabel
        Left = 24
        Top = 96
        Width = 125
        Height = 13
        Caption = 'CPUID[4] = FFFFFFFF'
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clWindowText
        Font.Height = -11
        Font.Name = 'MS Sans Serif'
        Font.Style = [fsBold]
        ParentFont = False
      end
      object Label5: TLabel
        Left = 16
        Top = 120
        Width = 273
        Height = 13
        Alignment = taCenter
        AutoSize = False
        Caption = 'Vendor'
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clWindowText
        Font.Height = -11
        Font.Name = 'MS Sans Serif'
        Font.Style = [fsBold]
        ParentFont = False
      end
      object FLabel: TLabel
        Left = 221
        Top = 48
        Width = 51
        Height = 13
        Alignment = taRightJustify
        Caption = 'Family = '
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clWindowText
        Font.Height = -11
        Font.Name = 'MS Sans Serif'
        Font.Style = [fsBold]
        ParentFont = False
      end
      object MLabel: TLabel
        Left = 222
        Top = 72
        Width = 50
        Height = 13
        Alignment = taRightJustify
        Caption = 'Model = '
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clWindowText
        Font.Height = -11
        Font.Name = 'MS Sans Serif'
        Font.Style = [fsBold]
        ParentFont = False
      end
      object PLabel: TLabel
        Left = 168
        Top = 24
        Width = 104
        Height = 13
        Alignment = taRightJustify
        Caption = 'Processor Type = '
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clWindowText
        Font.Height = -11
        Font.Name = 'MS Sans Serif'
        Font.Style = [fsBold]
        ParentFont = False
      end
      object SLabel: TLabel
        Left = 206
        Top = 96
        Width = 66
        Height = 13
        Alignment = taRightJustify
        Caption = 'Stepping = '
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clWindowText
        Font.Height = -11
        Font.Name = 'MS Sans Serif'
        Font.Style = [fsBold]
        ParentFont = False
      end
      object PValue: TLabel
        Left = 272
        Top = 24
        Width = 12
        Height = 13
        Caption = '??'
      end
      object FValue: TLabel
        Left = 272
        Top = 48
        Width = 12
        Height = 13
        Caption = '??'
      end
      object MValue: TLabel
        Left = 272
        Top = 72
        Width = 12
        Height = 13
        Caption = '??'
      end
      object SValue: TLabel
        Left = 272
        Top = 96
        Width = 12
        Height = 13
        Caption = '??'
      end
      object GetButton: TBitBtn
        Left = 8
        Top = 160
        Width = 137
        Height = 25
        Caption = 'CPUID'
        TabOrder = 0
        OnClick = GetButtonClick
        Kind = bkHelp
      end
      object CloseButton: TBitBtn
        Left = 160
        Top = 160
        Width = 137
        Height = 25
        TabOrder = 1
        Kind = bkClose
      end
    end
      

  2.   

    Function REGISTER_POS_CREATE(T_REG_NAME:STRING):BOOLEAN; //----把CPU的
    var
      Reg:TRegistry;
    begin
      Reg:=TRegistry.Create;
      try
        Reg.RootKey:=HKEY_LOCAL_MACHINE;
        if Reg.OpenKey(T_Reg_Name,True) then
          begin
            Reg.WriteDate('Run_First_date',date);
            Reg.WriteInteger('Cpu_id_Fourth',GetCpuId[4]);//----将CPU第四组号码存入注册表!
            Reg.WriteString('Sf_Id', '');
            Result:=True;
            end
            else
            Result:=False;
       Finally
         Reg.CloseKey;
         Reg.Free;
         end;
    end;