unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls,smart_drv;
type
TForm1 =
class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
function GetDriveTemp(drive:longint):byte;
procedure disktemp;
function GetHDDCount: integer;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure tform1.disktemp;
var
i:integer;
b:longint;
begin
ReadSMART;
for i:=0
to 3
do
begin
if hSMARTIOCTL[i] = INVALID_HANDLE_VALUE
then continue;
b:=GetDriveTemp(i);
end;
end;
function tform1.GetHDDCount: integer;
var f, i: integer;
begin
i := 0;
repeat
f := FileOpen('
\\.\PHYSICALDRIVE' + IntToStr(i), fmOpenRead
or fmShareDenyNone);
if f = -1
then break;
inc (i);
until false;
result := i;
end;
function tform1.GetDriveTemp(drive:longint):byte;
var i:longint;
begin
result:=0;
for i:=0
to 255
do
begin
if SCOP[ 0 ].attr[ i ].bAttrID=194
then
begin
result:=SCOP[ 0].attr[ i ].Raw[0];
break;
end;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
SmartResult: TSmartResult ;
begin
if GetHDDCount=1
then begin
Label1.caption:='
Disk 1 '+inttostr(GetDriveTemp(0))+'
°C';
end;
if GetHDDCount=3
then begin
Label1.caption:='
Disk 1 '+inttostr(GetDriveTemp(0))+'
°C';
Label2.caption:='
Disk 2 '+inttostr(GetDriveTemp(1))+'
°C';
Label3.caption:='
Disk 3 '+inttostr(GetDriveTemp(2))+'
°C';
form1.caption:=inttostr(SmartResult.Temperature);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
disktemp;
end;
end.