主题:[讨论]主板和CPU的标识。
wangshengli0208
[专家分:0] 发布于 2006-04-05 14:34:00
怎么才能查看主板和CPU的唯一标识。最好能用Delphi编程实现。
回复列表 (共1个回复)
沙发
sunriver [专家分:1330] 发布于 2006-04-05 15:41:00
CUPID的获得
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Button1: TButton;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
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 TForm1.Button1Click(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);
S := GetCPUVendor;
Label5.Caption := 'Vendor: ' + S; end
else begin
Label5.Caption := 'CPUID not available';
end;
end;
end.
我来回复