Solved

processor info

Posted on 2001-09-15
5
204 Views
Last Modified: 2010-04-06
how can i get the processor name and speed?

i would like them put into separate labels.

eg label1 = name
   label2 = speed


thanks


kevin ward
0
Comment
Question by:kevinward66
5 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6485413
Hello

  you can download free component with source from
http://www.torry.net/cpu.htm
0
 

Author Comment

by:kevinward66
ID: 6486021
if possible i would rather CODE than components!!!
0
 
LVL 1

Expert Comment

by:Dennis9
ID: 6486104
This code should do it:

function GetCPUSpeed: Double;
const
  DelayTime = 500; // measure time in ms
var
  TimerHi, TimerLo: DWORD;
  PriorityClass, Priority: Integer;
begin
  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);
end;

//Then just call it like
Label1.Caption := Format('%f MHz', [GetCPUSpeed]);



I can't remember if there is any special in the uses cluse, but if u have problems i will try to find what u need.

Dennis
0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 100 total points
ID: 6486197
Hello

  Here's a sample to get the cpu speed and name, I got the cpu name from the registry, and it's worked fine with my processor (AMD Athlon 900MHz)

Just add two labels, and one button, here's the complete code

//===========

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
uses Registry;

function GetCpuSpeed: string;
var
  t: DWORD;
  mhi, mlo, nhi, nlo: DWORD;
  t0, t1, chi, clo, shr32: Comp;
begin
  shr32 := 65536;
  shr32 := shr32 * 65536;
  t := GetTickCount;
  while t = GetTickCount do begin end;
  asm
    DB 0FH
    DB 031H
    mov mhi,edx
    mov mlo,eax
  end;

  while GetTickCount < (t + 1000) do begin end;
  asm
    DB 0FH
    DB 031H
    mov nhi,edx
    mov nlo,eax
  end;
  chi := mhi; if mhi < 0 then chi := chi + shr32;
  clo := mlo; if mlo < 0 then clo := clo + shr32;
  t0 := chi * shr32 + clo;
  chi := nhi; if nhi < 0 then chi := chi + shr32;
  clo := nlo; if nlo < 0 then clo := clo + shr32;
  t1 := chi * shr32 + clo;
  Result := FloatToStr((t1 - t0) / 1E6);
end;

function  GetCpuName : string;
var
  Registry: TRegistry;
  S:  string ;
begin
  Registry:=TRegistry.Create;
  Registry.RootKey:=HKEY_LOCAL_MACHINE;
  Registry.OpenKey('\Hardware\Description\System\CentralProcessor\0',False);
  Result :=Registry.ReadString('Identifier');
  Registry.Free;
end ;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1.Caption := GetCpuSpeed;
  Label2.Caption := GetCpuName;
end;
end.

Best regards
Mohammed Nasman
0
 
LVL 3

Expert Comment

by:VSF
ID: 6487288
At Simonets place u will find a sample called CPUID that returns to you processor speed and name, with source!
http://www.bhnet.com.br/~simonet/index.html

If u have any problems downloading or findig it, e-mail me and I'll send the complete sample to you!

Hope this helps!
VSF
www.victory.hpg.com.br
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question