Solved

processor info

Posted on 2001-09-15
5
202 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:mnasman
Comment Utility
Hello

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

Author Comment

by:kevinward66
Comment Utility
if possible i would rather CODE than components!!!
0
 
LVL 1

Expert Comment

by:Dennis9
Comment Utility
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:
mnasman earned 100 total points
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now