怎样取得主板和cpu序列号(50分)

  • 主题发起人 主题发起人 linlingwei
  • 开始时间 开始时间
L

linlingwei

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样取得主板和cpu序列号,立刻结账!
 
unit Main;

/////////////////////////////////////////////////////////////////////////////
// (c) NPS, 1997 - Idea, realisation, adoptation IsCPUID_Available) //
// kvk@estpak.ee //
// (c) Alex Abreu, 1997 - IsCPUID_Available source and idea //
// simonet@bhnet.com.br //
/////////////////////////////////////////////////////////////////////////////

interface

uses
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 := -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.
 
zcroot_0411说的没错,能够获得CPU的序列号,但是我使用这些代码在一批同型号机子实验时,发现有相同的号码出现,而且几率很到,我装近20台电脑,竟然只有15个不同的序列号,即有5个是与其他的号码相同。我觉得很奇怪。
 
接受答案了.
 
后退
顶部