各位大虾用label.caption显示Cpu序列号怎样实现?谢谢!

解决方案 »

  1.   

    TCPUID = array[1..4] of Longint;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;
    GetCPUID一个函数,愿在label.caption显示不用我说了吧
      

  2.   

    问题还没解决,当compile时assembler; register的;出错..............
      

  3.   

    "HKEY_LOCAL_MACHINE\hardware\DESCRIPTION\System\CentralProcessor\0"
    对应VendorIndentifier的值 
    把他找出来就可以了。
      

  4.   

    来个全套吧
    get the CPU name? 
    // this code will get the cpu identifier from the windows registryusesRegistry;function CPUname: string;varReg: TRegistry;beginCPUname := '';Reg := TRegistry.Create;tryReg.RootKey := HKEY_LOCAL_MACHINE;if Reg.OpenKey('\Hardware\Description\System\CentralProcessor\0', False) thenCPUname := Reg.ReadString('Identifier');finallyReg.Free;end;end; 
    { Get CPU type }function TForm1.GetCPUType: String;varkind: TCPUType;beginif winFlags and WF_CPU286 > 0 thenResult := '80286'elsebeginkind := CpuType;case kind ofi8086CPU:Result := '8086';i386CPU:Result := '80386';i486CPU:Result := '80486';iPentiumCPU:Result := 'Pentium';else{ Try to be flexible for future cpu types, e.g., P6. }Result := Format('P%d', [Ord(kind)]);end;end;end;{ Assembly function to get CPU type including Pentium and later }function TForm1.CpuType: TCPUType; assembler;asmpush DS{ First check for an 8086 CPU }{ Bits 12-15 of the FLAGS register are always set on the }{ 8086 processor. }pushf { save EFLAGS }pop bx { store EFLAGS in BX }mov ax,0fffh { clear bits 12-15 }and ax,bx { in EFLAGS }push ax { store new EFLAGS value on stack }popf { replace current EFLAGS value }pushf { set new EFLAGS }pop ax { store new EFLAGS in AX }and ax,0f000h { if bits 12-15 are set, then CPU }cmp ax,0f000h { is an 8086/8088 }mov ax, i8086CPU { turn on 8086/8088 flag }je @@End_CpuType{ 80286 CPU check }{ Bits 12-15 of the FLAGS register are always clear on the }{ 80286 processor. }{ Commented out because 'pop ax' crashes it to the DOS prompt when running }{ with a Delphi form on some Machines.}{ or bx,0f000h } { try to set bits 12-15 }{ push bx }{ popf }{ pushf }{ pop ax } { This crashes Delphi programs on some machines }{ and ax,0f000h } { if bits 12-15 are cleared, CPU=80286 }{ mov ax, i286CPU } { turn on 80286 flag }{ jz @@End_CpuType }{ To test for 386 or better, we need to use 32 bit instructions,but the 16-bit Delphi assembler does not recognize the 32 bit opcodesor operands. Instead, use the 66H operand size prefix to changeeach instruction to its 32-bit equivalent. For 32-bit immediateoperands, we also need to store the high word of the operand immediatelyfollowing the instruction. The 32-bit instruction is shown in a commentafter the 66H instruction.}{ i386 CPU check }{ The AC bit, bit #18, is a new bit introduced in the EFLAGS }{ register on the i486 DX CPU to generate alignment faults. }{ This bit can not be set on the i386 CPU. }db 66h { pushfd }pushfdb 66h { pop eax }pop ax { get original EFLAGS }db 66h { mov ecx, eax }mov cx,ax { save original EFLAGS }db 66h { xor eax,40000h }xor ax,0h { flip AC bit in EFLAGS }dw 0004hdb 66h { push eax }push ax { save for EFLAGS }db 66h { popfd }popf { copy to EFLAGS }db 66h { pushfd }pushf { push EFLAGS }db 66h { pop eax }pop ax { get new EFLAGS value }db 66h { xor eax,ecx }xor ax,cx { can't toggle AC bit, CPU=Intel386 }mov ax, i386CPU { turn on 386 flag }je @@End_CpuType{ i486 DX CPU / i487 SX MCP and i486 SX CPU checking }{ Checking for ability to set/clear ID flag (Bit 21) in EFLAGS }{ which indicates the presence of a processor }{ with the ability to use the CPUID instruction. }db 66h { pushfd }pushf { push original EFLAGS }db 66h { pop eax }pop ax { get original EFLAGS in eax }db 66h { mov ecx, eax }mov cx,ax { save original EFLAGS in ecx }db 66h { xor eax,200000h }xor ax,0h { flip ID bit in EFLAGS }dw 0020hdb 66h { push eax }push ax { save for EFLAGS }db 66h { popfd }popf { copy to EFLAGS }db 66h { pushfd }pushf { push EFLAGS }db 66h { pop eax }pop ax { get new EFLAGS value }db 66h { xor eax, ecx }xor ax, cxmov ax, i486CPU { turn on i486 flag }je @@End_CpuType { if ID bit cannot be changed, CPU=486 }{ without CPUID instruction functionality }{ Execute CPUID instruction to determine vendor, family, }{ model and stepping. The use of the CPUID instruction used }{ in this program can be used for B0 and later steppings }{ of the P5 processor. }db 66h { mov eax, 1 }mov ax, 1 { set up for CPUID instruction }dw 0db 66h { cpuid }db 0Fh { Hardcoded opcode for CPUID instruction }db 0a2hdb 66h { and eax, 0F00H }and ax, 0F00H { mask everything but family }dw 0db 66h { shr eax, 8 }shr ax, 8 { shift the cpu type down to the low byte }sub ax, 1 { subtract 1 to map to TCpuType }@@End_CpuType:pop dsend; { Get the Windows Flags to check for 286. The 286 assembly codecrashes due to a problem when using with Delphi Forms on some machines. Thismethod is safer.}procedure TForm1.FormCreate(Sender: TObject);beginwinFlags := GetWinFlags;end;{ Call the CPU function and assign it to the Edit box }procedure TForm1.BitBtn1Click(Sender: TObject);beginEdit1.Text := GetCPUType;end;end.{This code came from Lloyd's help file!} 
      

  5.   

    var-> kind: TCPUType;  begin
    .......[Error] Unit1.pas(48): Undeclared identifier: 'TCPUType'    
    是不是少了哪个.dcu文件???????
      

  6.   

    调用方法很简单:http://218.56.11.178:8020/web/index.aspx
    -》下载基地->例程-硬件控制->内存CPU硬盘检测
      

  7.   

    to :九品御厨
         谢谢大哥你了!
         
    ps:Wise Installation System - Professional Edition  比Install shield 还好吗?
      

  8.   

    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.