unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,WbemScripting_TLB,
activex, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
procedure WMIdata(Sender: TObject);
function GetWMIstring2 (wmiHost, wmiClass, wmiProperty :
string):
string;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.GetWMIstring2 (wmiHost, wmiClass, wmiProperty :
string):
string;
var // These are all needed for the WMI querying process
Locator: ISWbemLocator;
Services: ISWbemServices;
SObject: ISWbemObject;
ObjSet: ISWbemObjectSet;
SProp: ISWbemProperty;
Enum: IEnumVariant;
Value: Cardinal;
TempObj: OleVariant;
SN:
string;
begin
try
Locator := CoSWbemLocator.Create;
Services := Locator.ConnectServer(wmiHost, '
root\wmi', '
', '
', '
','
', 0,
nil);
ObjSet := Services.ExecQuery('
SELECT * FROM '+wmiClass, '
WQL',
wbemFlagReturnImmediately
and wbemFlagForwardOnly ,
nil);
Enum := (ObjSet._NewEnum)
as IEnumVariant;
while (Enum.Next(1, TempObj, Value) = S_OK)
do
begin
SObject := IUnknown(tempObj)
as ISWBemObject;
SProp := SObject.Properties_.Item(wmiProperty, 0);
if VarIsNull(SProp.Get_Value)
then
result := '
'
else
begin
SN := SProp.Get_Value;
result := SN;
end;
end;
except
on exception do
result := '
';
end;
end;
procedure TForm1.WMIdata(Sender: TObject);
var tmpstr :
string; cputemp : Integer;
begin
tmpstr := getWMIstring2('
','
MSAcpi_ThermalZoneTemperature','
CurrentTemperature');
if tmpstr <> '
'
then
Begin
cputemp:= (StrToInt(tmpstr) - 2732)
div 10;
form1.caption := IntToStr(cputemp) + '
°C'
end else
form1.Caption := '
ERROR';
end;
procedure TForm1.Button1Click(Sender: TObject);
var tmpstr :
string; cputemp : Integer;
begin
tmpstr := getWMIstring2('
','
MSAcpi_ThermalZoneTemperature','
CurrentTemperature');
if tmpstr <> '
'
then
Begin
cputemp:= (StrToInt(tmpstr) - 2732)
div 10;
form1.caption := IntToStr(cputemp) + '
°C'
end else
form1.Caption := '
ERROR';
end;
end.