unit Unit2;
//2ß140914
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls,
ActiveX, ComObj,
Vcl.OleAuto;
type
TForm2 =
class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form2: TForm2;
OHM : Boolean;
const
WbemUser ='
'; WbemPassword ='
'; WbemComputer ='
localhost'; wbemFlagForwardOnly = $00000020;
implementation
{$R *.dfm}
procedure MM(s:
string);
begin Form2.Memo1.Lines.Add(s);
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
Close;
end;
procedure GetSensorInfo;
var
FSWbemLocator, FWMIService, FWbemObjectSet, FWbemObject : OLEVariant;
oEnum : IEnumvariant; iValue : LongWord;
begin;
FSWbemLocator := CreateOleObject('
WbemScripting.SWbemLocator');
FWMIService :=
FSWbemLocator.ConnectServer(WbemComputer, '
root\OpenHardwareMonitor', WbemUser, WbemPassword);
FWbemObjectSet:= FWMIService.ExecQuery('
SELECT * FROM Sensor','
WQL',wbemFlagForwardOnly);
oEnum := IUnknown(FWbemObjectSet._NewEnum)
as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0
do
begin
MM(Format('
Identifier %s',[
String(FWbemObject.Identifier)]));
// String
MM(Format('
Index %d',[Integer(FWbemObject.
Index)]));
// Sint32
MM(Format('
InstanceId %s',[
String(FWbemObject.InstanceId)]));
// String
MM(Format('
Max %n',[Double(FWbemObject.Max)]));
// Real32
MM(Format('
Min %n',[Double(FWbemObject.Min)]));
// Real32
MM(Format('
Name %s',[
String(FWbemObject.
Name)]));
// String
MM(Format('
Parent %s',[
String(FWbemObject.Parent)]));
// String
MM(Format('
ProcessId %s',[
String(FWbemObject.ProcessId)]));
// String
MM(Format('
SensorType %s',[
String(FWbemObject.SensorType)]));
// String
MM(Format('
Value %n',[Double(FWbemObject.Value)]));
// Real32
MM('
----------------------------------------------------------------------');
end;
FWbemObject:=Unassigned;
end;
procedure GetSensorCPUTEMP;
var
FSWbemLocator, FWMIService, FWbemObjectSet, FWbemObject : OLEVariant;
oEnum : IEnumvariant; iValue : LongWord;
begin;
OHM:= false;
FSWbemLocator := CreateOleObject('
WbemScripting.SWbemLocator');
FWMIService := FSWbemLocator.ConnectServer(WbemComputer, '
root\OpenHardwareMonitor', WbemUser, WbemPassword);
FWbemObjectSet:=
FWMIService.ExecQuery('
SELECT * FROM Sensor WHERE Name LIKE "%CPU %" AND SensorType = "Temperature"','
WQL',wbemFlagForwardOnly);
oEnum := IUnknown(FWbemObjectSet._NewEnum)
as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0
do
begin
MM(Format('
Name: %s',[
String(FWbemObject.
Name)]));
// String
MM(Format('
SensorType %s',[
String(FWbemObject.SensorType)]));
// String
MM(Format('
Value: %n',[Double(FWbemObject.Value)]));
// Real32
MM('
');
end;
OHM:= true;
FWbemObject:=Unassigned;
end;
procedure GetSensorCPULOAD;
var
FSWbemLocator, FWMIService, FWbemObjectSet, FWbemObject : OLEVariant;
oEnum : IEnumvariant; iValue : LongWord;
begin;
OHM:= false;
FSWbemLocator := CreateOleObject('
WbemScripting.SWbemLocator');
FWMIService := FSWbemLocator.ConnectServer(WbemComputer, '
root\OpenHardwareMonitor', WbemUser, WbemPassword);
FWbemObjectSet:=
FWMIService.ExecQuery('
SELECT * FROM Sensor WHERE Name LIKE "%CPU %" AND SensorType = "Load"','
WQL',wbemFlagForwardOnly);
oEnum := IUnknown(FWbemObjectSet._NewEnum)
as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0
do
begin
MM(Format('
Name: %s',[
String(FWbemObject.
Name)]));
// String
MM(Format('
SensorType %s',[
String(FWbemObject.SensorType)]));
// String
MM(Format('
Value: %n',[Double(FWbemObject.Value)]));
// Real32
MM('
');
end;
OHM:= true;
FWbemObject:=Unassigned;
end;
procedure GetSensorHDD;
var
FSWbemLocator, FWMIService, FWbemObjectSet, FWbemObject : OLEVariant;
oEnum : IEnumvariant; iValue : LongWord;
begin;
OHM:= false;
FSWbemLocator := CreateOleObject('
WbemScripting.SWbemLocator');
FWMIService :=
FSWbemLocator.ConnectServer(WbemComputer, '
root\OpenHardwareMonitor', WbemUser, WbemPassword);
FWbemObjectSet:=
FWMIService.ExecQuery('
SELECT * FROM Sensor WHERE Name = "Temperature" AND SensorType = "Temperature"','
WQL',wbemFlagForwardOnly);
oEnum := IUnknown(FWbemObjectSet._NewEnum)
as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0
do
begin
MM(Format('
Name: %s',[
String(FWbemObject.
Name)]));
// String
MM(Format('
SensorType %s',[
String(FWbemObject.SensorType)]));
// String
MM(Format('
Value: %n',[Double(FWbemObject.Value)]));
// Real32
end;
OHM:= true;
FWbemObject:=Unassigned;
end;
procedure GetSensorGPU;
var
FSWbemLocator, FWMIService, FWbemObjectSet, FWbemObject : OLEVariant;
oEnum : IEnumvariant; iValue : LongWord;
begin;
OHM:= false;
FSWbemLocator := CreateOleObject('
WbemScripting.SWbemLocator');
FWMIService :=
FSWbemLocator.ConnectServer(WbemComputer, '
root\OpenHardwareMonitor', WbemUser, WbemPassword);
FWbemObjectSet:=
// FWMIService.ExecQuery('SELECT * FROM Sensor WHERE Name LIKE "%GPU Core%" AND SensorType = "Temperature"','WQL',wbemFlagForwardOnly);
// FWMIService.ExecQuery('SELECT * FROM Sensor WHERE Name LIKE "%GPU %" AND SensorType = "Temperature"','WQL',wbemFlagForwardOnly);
FWMIService.ExecQuery('
SELECT * FROM Sensor WHERE Name LIKE "%GPU %"','
WQL',wbemFlagForwardOnly);
oEnum := IUnknown(FWbemObjectSet._NewEnum)
as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0
do
begin
MM(Format('
Name: %s',[
String(FWbemObject.
Name)]));
// String
MM(Format('
SensorType %s',[
String(FWbemObject.SensorType)]));
// String
MM(Format('
Value: %n',[Double(FWbemObject.Value)]));
// Real32
MM('
');
end;
OHM:= true;
FWbemObject:=Unassigned;
end;
procedure TForm2.Button2Click(Sender: TObject);
//HDD
begin Memo1.Clear;
GetSensorHDD;
end;
procedure TForm2.Button3Click(Sender: TObject);
begin Memo1.Clear;
GetSensorInfo;
end;
procedure TForm2.Button4Click(Sender: TObject);
begin Memo1.Clear;
GetSensorGPU;
end;
procedure TForm2.Button5Click(Sender: TObject);
begin Memo1.Clear;
GetSensorCPUTEMP;
end;
procedure TForm2.Button6Click(Sender: TObject);
begin Memo1.Clear;
GetSensorCPULOAD;
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
Form2.Height:= Screen.Height-20;
Memo1.Height:= Screen.Height-80;
end;
procedure TForm2.FormShow(Sender: TObject);
begin
Application.Title := '
OHM-2014';
GetSensorInfo;
end;
end.