JohnOne

CPU Temp

10 posts in this topic

I have been using some code to put laptop in to sleep mode when the cpu temp goes over 97 degrees for a number of seconds.

Problem is, it has stopped working sometime over the last couple of months, and just reports 0 as the cpu temp.

I don't think anything has changed on my win 10 x64 OS other than updates.

Here is the code I use...

#RequireAdmin

#include <Date.au3>


$oMyError = ObjEvent("AutoIt.Error", "ErrFunc")

HotKeySet("{INSERT}", Show)

FileDelete("log.txt")


$file = FileOpen("log.txt", 1)
$toohotcount = 0
$sleep = False
While 3
    $temp = _ACPI_Temp()
    FileWrite($file, $temp & @TAB & _Now() & @CRLF)
    ;ConsoleWrite($temp & @LF)
    If $temp >= 97 Then
        $toohotcount += 1
        If $toohotcount >= 4 Then
            FileWrite($file, $temp & @TAB & _Now() & " ##### Whoops!" & @CRLF)
            $toohotcount = 0
            ;FileClose($file)
            _ComputerSleep()
        EndIf
    Else
        $toohotcount = 0
    EndIf

    Sleep(10000)
WEnd

Func Show()
    MsgBox(0, 0, _ACPI_Temp())
EndFunc   ;==>Show

Func _ComputerSleep()
    Beep(400, 1000)
    Shutdown(32)
EndFunc   ;==>_ComputerSleep


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



Func ErrFunc()
    Beep(400, 1000)
    Shutdown(32)
EndFunc   ;==>ErrFunc

Or just use the following to test...

MsgBox(0, 0, _ACPI_Temp())

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

Can anyone think why this code might have suddenly stopped doing what it did, correctly?


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites



Hi @JohnOne it's been a while I did not see you around here... nice to see you again :)

seems that your script needs admin rights to work...

#RequireAdmin

MsgBox(0, 0, _ACPI_Temp())

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

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

without admin I get N/A,

with admin I get 55.5

Win7 enterprise x64


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

same temp in a cmd window using this wmic command:

wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature /value

 

Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

I get N/A regardless.

and the wmic cmd says "not supported"

Its win10x64


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

 

Share this post


Link to post
Share on other sites

You can use the SDK from Core Temp to get the CPU temp.

 

This is what I did in 2014:

#cs
Shared memory implementation in Core Temp:

Core Temp shares the following structure:

typedef struct core_temp_shared_data
{
    unsigned int    uiLoad[256];
    unsigned int    uiTjMax[128];
    unsigned int    uiCoreCnt;
    unsigned int    uiCPUCnt;
    float       fTemp[256];
    float       fVID;
    float       fCPUSpeed;
    float       fFSBSpeed;
    float       fMultipier;
    char        sCPUName[100];
    unsigned char   ucFahrenheit;
    unsigned char   ucDeltaToTjMax;
}CORE_TEMP_SHARED_DATA,*PCORE_TEMP_SHARED_DATA,**PPCORE_TEMP_SHARED_DATA;

unsigned int is a 32bit unsigned integer.
unsigned char is 8bit (1 byte) in size.

ucFahrenheit and ucDeltaToTjMax represent boolean values. 0 = false, 1 = true.
If ucFahrenheit is set, the temperature is reported in Fahrenheit.
If ucDeltaToTjMax is set, the temperature reported respresents the distance from TjMax.

Core Temp's shared area is named: "CoreTempMappingObject".

C++ Dynamic Link Library:

This DLL was written in C++, and it can be easily used with most programming languages.
There is only a single function. Here is the internal function declaration:

bool __declspec(dllimport) fnGetCoreTempInfo(CORE_TEMP_SHARED_DATA *&pData);

You can declare it in your program in the following manner:

typedef bool (*fnGetCoreTempInfo)(CORE_TEMP_SHARED_DATA *&pData);
fnGetCoreTempInfo GetCoreTempInfo;

For compatibility with some programming languages a function was added.
It uses Win32 API calling convention and is declared as follows:

bool WINAPI fnGetCoreTempInfoAlt(CORE_TEMP_SHARED_DATA *pData);

typedef bool (*fnGetCoreTempInfoAlt)(CORE_TEMP_SHARED_DATA *pData);
fnGetCoreTempInfoAlt GetCoreTempInfo;

Usage:

    * Declare a pointer to CORE_TEMP_SHARED_DATA structure and allocate it.
      It is also recommended to fill the allocated memory with NULL to avoid possible problems.
    * Call the function using the pointer to CORE_TEMP_SHARED_DATA structure as an argument.
      The function will fill the structure if the shared memory was successfully read.
    * The function returns 'true' if succeeded and 'false' if it failed. You can use GetLastError() in case the function fails.
    * In case the function fails due to an exception GetLastError() returns UNKNOWN_EXCEPTION (0x20000000)
#ce
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Run_After=upx.exe --best --lzma "%out%"
#AutoIt3Wrapper_Run_After=del /f /q GetCoreTempInfo_stripped.au3

If Not FileExists(@ScriptDir & "\GetCoreTempInfo.dll") And (Not ProcessExists("Core Temp.exe") Or Not ProcessExists("Core Temp x64.exe")) Then
    MsgBox(16,"Error", "Core Temp.exe läuft und/oder GetCoreTempInfo.dll existiert nicht", 20)
    Exit
EndIf
$dll = DllOpen(@ScriptDir & "\GetCoreTempInfo.dll")

$CORE_TEMP_SHARED_DATA = DllStructCreate("uint uiLoad[256];"    & _
                                         "uint uiTjMax[128];"   & _
                                         "uint uiCoreCnt;"      & _
                                         "uint uiCPUCnt;"       & _
                                         "float fTemp[256];"    & _
                                         "float fVID;"          & _
                                         "float fCPUSpeed;"     & _
                                         "float fFSBSpeed;"     & _
                                         "float fMultipier;"    & _
                                         "char sCPUName[100];"  & _
                                         "ubyte ucFahrenheit;"  & _
                                         "ubyte ucDeltaToTjMax")

$call = DllCall($dll, "int", "fnGetCoreTempInfoAlt", "struct*", $CORE_TEMP_SHARED_DATA)

$CPU_Name = $CORE_TEMP_SHARED_DATA.sCPUName
$CPU_Speed = Round($CORE_TEMP_SHARED_DATA.fCPUSpeed,0)
$CPU_Cores = $CORE_TEMP_SHARED_DATA.uiCoreCnt
$CPU_FSB_Speed = Round($CORE_TEMP_SHARED_DATA.fFSBSpeed, 0)
$CPU_Multiplicator = $CORE_TEMP_SHARED_DATA.fMultipier
$CPU_Temp = ""
For $i = 1 To $CPU_Cores
    $CPU_Temp &= $CORE_TEMP_SHARED_DATA.fTemp(($i)) & "°/ "
Next
$CPU_Temp = StringTrimRight($CPU_Temp, 2)

MsgBox(0,"Core Temp", _
        "CPU Name: " & $CPU_Name & @CRLF & _
        "CPU Speed: " & $CPU_Speed & " MHz" & @CRLF & _
        "CPU Cores: " & $CPU_Cores & @CRLF & _
        "CPU FSB Speed: " & $CPU_FSB_Speed & " MHz" & @CRLF & _
        "CPU Multiplicator: " & $CPU_Multiplicator & @CRLF & _
        "CPU Temp: " & $CPU_Temp & " C", 30)

$CORE_TEMP_SHARED_DATA = 0
DllClose($dll)

 


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
3 hours ago, UEZ said:

You can use the SDK from Core Temp to get the CPU temp.

The DLL uses Core Temp's shared memory feature to read the data.

You need to run "Core Temp.exe" first, so that DLL reads data from shared memory!
I think that is an inconvenience.


Regards,
 

Share this post


Link to post
Share on other sites

#10 ·  Posted

Hi  not sure if you worked this out yet but here's the console output on my Win 10 Pro which shows what's going wrong on my PC

>-- Debug --> 1
-- debug --> 3072
-- debug --> 2732

HTH

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