Jump to content

Refresh CPU Temp


Recommended Posts

I was having a look at the CPU Temp script by chris L

Func _ACPI_Temp()
Local $wbemFlagReturnImmediately = 0x10, $strComputer, $objWMIService, $colItems
Local $wbemFlagForwardOnly = 0x20
Local $CurrTemp = "N/A"
$strComputer = "."
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\wmi")
$colItems = $objWMIService.ExecQuery("SELECT * FROM MSAcpi_ThermalZoneTemperature", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
For $objItem In $colItems
$CurrTemp = ($objItem.CurrentTemperature - 2732) / 10
Next
Return $CurrTemp
EndFunc ;==>_ACPI_Temp

And it gives me the temp as expected, the thing i dont know is how to get it to refresh the temp every 30 secs?

Any suggestions?

Could i use ContinueLoop here

For $objItem In $colItems
$CurrTemp = ($objItem.CurrentTemperature - 2732) / 10
Next

but how do i get it to understand every 30 secs?

Link to comment
Share on other sites

Its on a Gui where it just shows the temp as a number but i want it to fluctuate as the temps rise and fall.

Its only an indication so if we see high temps we investigate so automated is better as we are not always at the machine and we can pass by and just check

Edited by Chimaera
Link to comment
Share on other sites

huh?

Local Const $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20
Local Const $strComputer = "."

Local Const $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\wmi")

While 1
    ConsoleWrite(_ACPI_Temp() & @CrLf)
    Sleep(30000)
WEnd

Func _ACPI_Temp()
    Local $CurrTemp = "N/A"

    Local Const $colItems = $objWMIService.ExecQuery("SELECT * FROM MSAcpi_ThermalZoneTemperature", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    For $objItem In $colItems
        $CurrTemp = ($objItem.CurrentTemperature - 2732) / 10
    Next

    Return $CurrTemp
EndFunc   ;==>_ACPI_Temp

For your case it would be better to set a timer on your GUI instead of this sleep.

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

  • Moderators

FireFox beat me to it, but I was thinking of separating the two, in case you want to change only the temp function later. Something like this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $temp
AdlibRegister("_tempchange", 10000)

Local $msg
   GUICreate("My CPU Temp GUI", 300, 300)
   $temp = GUICtrlCreateLabel("", 10, 10, 100, 40)
   GUISetState(@SW_SHOW)
      While 1
         $msg = GUIGetMsg()
            Select
               Case $msg = $GUI_EVENT_CLOSE
               ExitLoop
            EndSelect
      WEnd

GUIDelete()

Func _tempchange()

Local $wbemFlagReturnImmediately = 0x10, $strComputer, $objWMIService, $colItems
Local $wbemFlagForwardOnly = 0x20
Local $CurrTemp = "N/A"
$strComputer = "."
 
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\wmi")
$colItems = $objWMIService.ExecQuery("SELECT * FROM MSAcpi_ThermalZoneTemperature", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

   For $objItem In $colItems
      $CurrTemp = ($objItem.CurrentTemperature - 2732) / 10
   Next

GUICtrlSetData($temp, $CurrTemp)

EndFunc

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Hi,

I tried the MSAcpi_ThermalZoneTemperature but it does not retrieve the correct temperature from the CPU

http://openhardwaremonitor.org/files/openhardwaremonitor-v0.5.1-beta.zip

Open hardware monitor does, i must be possible to retrieve the temperature through a dll. I don't know how.. in the supplied example openhardwaremonitor.exe must be resident .

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

If not ProcessExists("OpenHardwareMonitor.exe") Then
Msgbox (16, "Error", "Please start OpenHardwareMonitor.exe")
Exit
EndIf
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$strComputer = "."
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\OpenHardwareMonitor")

GUICreate ("CPU", 200,200)

GUICtrlCreateLabel ("Temperature", 10, 10, 100,20)
GUICtrlCreateLabel ("Load", 10, 40, 100,20)
GUICtrlCreateLabel ("Power", 10, 70, 100,20)

$CPUTemp = GUICtrlCreateLabel("", 130, 10, 50, 20, $SS_RIGHT)
$CPULoad = GUICtrlCreateLabel("", 130, 40, 50, 20, $SS_RIGHT)
$CPUPower = GUICtrlCreateLabel("", 130, 70, 50, 20, $SS_RIGHT)

GUISetState()

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch

$colItems = $objWMIService.ExecQuery("SELECT * FROM Sensor", "WQL",$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
$Output=""
$Power=""
$Load=""
For $objItem in $colItems
if $objItem.SensorType = 'Power' and StringInStr($objItem.Parent, 'cpu') Then
If StringInStr($objItem.Name , "Package") Then
_GuiCtrlSetData($CPUPower, Round($objItem.Value,1) & " W")
EndIf
EndIf
if $objItem.SensorType = 'Temperature' and StringInStr($objItem.Parent, 'cpu') Then
If StringInStr($objItem.Name , "Package") Then
_GuiCtrlSetData($CPUTemp, $objItem.Value & " °C")
EndIf
EndIf
if $objItem.SensorType = 'Load' and StringInStr($objItem.Parent, 'cpu') Then
If StringInStr($objItem.Name , "Total") Then
_GuiCtrlSetData($CPULoad, Round($objItem.Value,1) & " %")
EndIf
EndIf
Next
WEnd

Func _GUICtrlSetData($iCtrlID, $sData)
If GUICtrlRead($iCtrlID, 1) <> $sData Then GUICtrlSetData($iCtrlID, $sData)
EndFunc ;==>_GUICtrlSetData

Best regards,Emiel Wieldraaijer

Link to comment
Share on other sites

Thx Emiel

But im just looking for a basic indication, We use Aida if i really need to know whats going on

I dont really want to add another program into the mix.

Its a shame like you say that it cant be accessed from a dll etc.

Link to comment
Share on other sites

  • 2 weeks later...

Think im going to have to revist this as ive found a flaw

because its polling the consolewrite every 20 secs it stops the other buttons working in the gui

Lol ill have to look at the other suggestions and see what else can be done

Link to comment
Share on other sites

This setup

Func _ACPI_Temp()
    Local $wbemFlagReturnImmediately = 0x10, $strComputer, $objWMIService, $colItems
    Local $wbemFlagForwardOnly = 0x20
    Local $CurrTemp = "N/A"
    $strComputer = "."
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\wmi")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM MSAcpi_ThermalZoneTemperature", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    For $objItem In $colItems
        $CurrTemp = ($objItem.CurrentTemperature - 2732) / 10
        ;$Critical = ($objItem.CriticalTripPoint - 2732) / 10
    Next
    Return $CurrTemp
EndFunc ;==>_ACPI_Temp

and this in the while /wend

ConsoleWrite(_ACPI_Temp() & @CrLf) ; Refreshes CPU Temp Funtion
    Sleep(20000) ;                       Every 20 Secs
Link to comment
Share on other sites

Yep i have no idea as i never use anything like that

I only write simple install programs and a bit of robocopy CMD stuff, im not a programmer I never deal with stuff like this till now

Ill have a play with the examples and see what i can get working ;)

Edited by Chimaera
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...