Recent

Author Topic: WMI Disk temperature  (Read 1706 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 939
WMI Disk temperature
« on: January 22, 2022, 05:26:56 pm »
Not quite sure where to ask this but
 
How can I get the temperature of a hard drive using WMI?

I can't get my head around all the VB / Powershell stuff on the net.

Thanks.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1115
Re: WMI Disk temperature
« Reply #1 on: January 23, 2022, 08:08:27 am »
hello,
you can try my modified wmi utility utilwmi
to use the MSStorageDriver_ATAPISmartData wmi class you must change the wmi name space to root\WMI :
in utilwmi :
Code: Pascal  [Select][+][-]
  1. objWMIService   := FSWbemLocator.ConnectServer('localhost', 'root\WMI', '', '');

the class MSStorageDriver_ATAPISmartData doesn't work for all disk drive and as the temperature is a vendorspecific property the index can change according to manufacturer.
Here is a code to read the temperature from my WD hard disk  (you must execute application as administrator ) :
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button10Click(Sender: TObject);
  2.   var WMIResult         : TFPObjectList;
  3.       f                 : integer;
  4.       retVal            : String;
  5.       temperature       : String;
  6.   begin
  7.     WMIResult := GetWMIInfo('MSStorageDriver_ATAPISmartData', ['InstanceName','VendorSpecific']);
  8.     for f := 0 to Pred(WMIResult.Count) do
  9.     begin
  10.       retVal := TStringList(WMIResult[f]).ValueFromIndex[0];
  11.       Memo1.Lines.add(Retval);
  12.       retVal := TStringList(WMIResult[f]).ValueFromIndex[1];
  13.       temperature := retVal.Split(',')[163];
  14.       Memo1.Lines.add('temperature : ' + temperature + ' °C');
  15.     end;
  16.  
  17.     WMIResult.Free;
  18.   end;

Result in attachment

Friendly, J.P
« Last Edit: January 23, 2022, 08:16:01 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

pcurtis

  • Hero Member
  • *****
  • Posts: 939
Re: WMI Disk temperature
« Reply #2 on: January 23, 2022, 01:02:45 pm »
OK. Thanks I got it to work.

I have a Toshiba, the index is 199.

Thanks.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

 

TinyPortal © 2005-2018