# VBForums CodeBank > CodeBank - Other >  [DELPHI] - Get CPU Usage

## Madboy

```
uses 
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
  ComCtrls, CommCtrl, StdCtrls, Menus,WinSpool, ExtCtrls, Buttons, Registry; 

type 
  TForm1 = class(TForm) 
    Button1: TButton; 
    Label1: TLabel; 
    Label2: TLabel; 
    Timer1: TTimer; 
    Button2: TButton; 
    procedure Button1Click(Sender: TObject); 
    procedure Button2Click(Sender: TObject); 
    procedure Timer1Timer(Sender: TObject); 
  private 
    { Private declarations } 
    started : boolean; 
    reg : TRegistry; 
  public 
    { Public declarations } 
  end; 

var 
  Form1: TForm1; 

implementation 

{$R *.DFM} 

procedure TForm1.Button1Click(Sender: TObject); 
var 
  Dummy : array[0..1024] of byte; 
begin 

  Reg:=TRegistry.Create; 
  Reg.RootKey:=HKEY_DYN_DATA; topic 
  Reg.OpenKey('PerfStats\StartStat',false) 
  Reg.ReadBinaryData('KERNEL\CPUUsage',Dummy,Sizeof(Dummy)); 
  Reg.CloseKey; 
  started:=true; 
end; 

procedure TForm1.Timer1Timer(Sender: TObject); 
var 
  CPUU : integer; 
begin 
  if started then 
  begin 
    Reg.OpenKey('PerfStats\StatData',false);
    Reg.ReadBinaryData('KERNEL\CPUUsage',CPUU,SizeOf(Integer)); 
    Reg.CloseKey; 
    Label1.Caption:=IntToStr(CPUU)+'%'; 
  end; 
end; 

procedure TForm1.Button2Click(Sender: TObject); 
var 
  Dummy : array[0..1024] of byte; 
begin 
  Reg.OpenKey('PerfStats\StopStat',false); 
  Reg.ReadBinaryData('KERNEL\CPUUsage',Dummy,SizeOf(Dummy)); 
  Reg.Free; 
  Started:=false; 
end; 

end.
```

----------

