Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 10-01-2001, 10:16 AM
al_b al_b is offline
Member
 
Join Date: Feb 2001
Posts: 57
Default How can i get a processor serial number ?

How can i get a CPU serial number ?

---===Alex===---
---===B.===---
Reply With Quote
  #2  
Old 10-01-2001, 11:48 AM
gLes gLes is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,273
Default RE: How can i get a processor serial number ?

Here's some code from good old bwd...hope he doesn't mind I posted it instead of him...

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;

Function Getcpu : String;
var
CPUID : TCPUID;

S : TVendor;
begin
if IsCPUID_Available then begin
CPUID := GetCPUID;
S := GetCPUVendor;
getcpu := S; end
else begin
getcpu := 'Unknown Chip';
end;
end;

function GetCPUSpeed: Double;
const
DelayTime = 500;
var
TimerHi, TimerLo: DWORD;
PriorityClass, Priority: Integer;
begin
try
PriorityClass := GetPriorityClass(GetCurrentProcess);
Priority := GetThreadPriority(GetCurrentThread);

SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);

Sleep(10);
asm
dw 310Fh // rdtsc
mov TimerLo, eax
mov TimerHi, edx
end;
Sleep(DelayTime);
asm
dw 310Fh // rdtsc
sub eax, TimerLo
sbb edx, TimerHi
mov TimerLo, eax
mov TimerHi, edx
end;

SetThreadPriority(GetCurrentThread, Priority);
SetPriorityClass(GetCurrentProcess, PriorityClass);

Result := TimerLo / (1000.0 * DelayTime);
except end;
end;




then use this for the CPU speed:

cpuspeed:=Format('%f MHz', [GetCPUSpeed]);

here is something for drives also:

Procedure tmainsys.Drives;
var
D1 : set of 0..25;
D2, ScreenWidth, ScreenHeight : integer;
Drives, wid : String;
dc, DeskHWnd: HDC;
memstat: TMemoryStatus;
begin
DWORD( D1 ) := Windows.GetLogicalDrives;
begin
for D2 := 0 to 25 do
if D2 in D1 then
Drives := Drives + Chr( D2 + Ord( 'A' )) + ': ';
end;

Sendback('Comp Name - '+Hostname);
sendback(winver+ ' Host time - '+TimeToStr(Time));
Sendback('Windows Key '+pkey );
sendback('System Up Time - '+systemup);
wid:=getcpu;
sendback('CPU - '+wid+' '+cpuspeed);

Try

GlobalMemoryStatus(memstat);
D2:=(memstat.dwTotalPhys);
D2:=D2 div 1020;
D2:=D2 div 1020;
wid:=IntToStr(D2);
Sendback(wid +' MB of RAM');
except
Sendback('Unknown Ammount Of RAM');
end;

Sendback('Host Drives - ' + Drives);

Sendback('Host Windows Dir - ' + WindowsDir);
DeskHWnd := GetDeskTopWindow;
dc := GetDC(DeskHWnd);
ScreenWidth := GetDeviceCaps(dc,HORZRES);
ScreenHeight := GetDeviceCaps(dc,VERTRES);
drives:=inttostr(Screenheight);
Wid:=inttostr(screenwidth);
Sendback('Screen Resolution :'+wid+'*'+Drives);
if GetSystemMetrics(SM_NETWORK) AND $01 = $01 then
Sendback('Machine has network devices installed');
end;



yes, it has a few functions mentioned in there, but dont worry about them, they are only for displaying the data.

see you arround, bye!

----------------------------
[b-w-d.net]
webmaster@b-w-d.net

Hope that helps...

gLes

"Small step for me, but large step for all Delphi developers!"
/gLes@hab.hu/

Remeber all who have died at the WTC and let the ones responsible get the punishment they deserve!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 03:24 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2014, vBulletin Solutions, Inc.