获取CPU序列号

Unit CPUID;

{***********************************************
* 这个模块是用来获取CPU序列号,调用方式: *
* 在上层程序的uses子句中含CPUID模块,用函数 *
*调用 CPUID.GetCPUVendor 获得CPU的制造商名称; *
*调用 CPUID.GetCPUInfo 得到CPU的序列号. *
*************************************************}

interface

uses
SysUtils;

type
TCPUID = array[1..4] of Longint;
TVendor = array [0..11] of char;

function GetCPUID: TCPUID; assembler; register;
function GetCPUVendor: TVendor; assembler; register;
function GetCPUInfo: string;

implementation

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;

Function GetCPUInfo: string;
var
CPUID: TCPUID;
I: Integer;
begin
for I := Low(CPUID) to High(CPUID) do
CPUID[I] := -1;
CPUID := GetCPUID;
Result := IntToHex(CPUID[1], 8) + IntToHex(CPUID[2], 8)
+ IntToHex(CPUID[3], 8)
+ IntToHex(CPUID[4], 8);
end;

end.

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注

− 5 = 2