Jump to content
Sign in to follow this  
Chimaera

Refresh CPU Temp

Recommended Posts

Chimaera

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?

Share this post


Link to post
Share on other sites
FireFox

What about executing the query every 30 seconds ?


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
JLogan3o13

I agree with FireFox, I would just set a HotKey to call the query every 30 seconds.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Chimaera

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

Share this post


Link to post
Share on other sites
FireFox

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

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
JLogan3o13

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
  • Like 1

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Emiel Wieldraaijer

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

Share this post


Link to post
Share on other sites
Chimaera

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.

Share this post


Link to post
Share on other sites
Chimaera

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

Share this post


Link to post
Share on other sites
FireFox

Which script are you using ?


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Chimaera

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

Share this post


Link to post
Share on other sites
FireFox

Are you going to tell me that you don't know the existence of these functions : TimerInit/Diff, AdlibRegister, _WinAPI_SetTimer/_Timer_Init ?


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Chimaera

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

Share this post


Link to post
Share on other sites
FireFox

Sorry if I seemed hard, I wanted to point out that it's not difficult.

If you need any help, you know what to do ;)

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
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
Sign in to follow this  

×