Einzelnen Beitrag anzeigen

hathor
(Gast)

n/a Beiträge
 
#1

OPENHARDWAREMONITOR mit WMI

  Alt 14. Sep 2014, 00:16
Der OPENHARDWAREMONITOR mit WMI-Server stellt die Daten für weitere Verwendung zur Verfügung.
http://openhardwaremonitor.org/

Leider enthält er einige kleine Fehler, z.B. einige Bezeichnungen sind falsch...
Die Variable OHM : Boolean; hat in dieser DEMO keine Bedeutung.

Delphi-Quellcode:
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.
Tags:
CPU, GPU, HDD Temperaturen und sonstiges
Temperaturen lesen (CPU,HDD...)
Miniaturansicht angehängter Grafiken
ohm-2014.jpg  
Angehängte Dateien
Dateityp: zip OHM-20140913.zip (718,0 KB, 241x aufgerufen)

Geändert von hathor (14. Sep 2014 um 10:18 Uhr)
  Mit Zitat antworten Zitat