Jump to content

CPU Temp


JohnOne
 Share

Recommended Posts

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.

Link to comment
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

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
Share on other sites

same temp in a cmd window using this wmic command:

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

 

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
Share on other sites

I get N/A regardless.

and the wmic cmd says "not supported"

Its win10x64

Spoiler

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

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

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

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

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.

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

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

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • 4 years later...

Using the  SAcpi_ThermalZoneTemperature from wmic is a bad idea. In gneral this returns temperatures from different areas on the Motherboard not the CPU Temp and the drivers need to support it. On my Ryzen I also get values that make no sense like 160°C (value of 4002, 3302, etc.) unless these values are in Degrees Fahrenheit so you even don't know if it's in Degrees Celsius or Fahrenheit.

The Solution Posted by @UEZ still works but the description is bit short even with additional comment from @VIP it took me some time to figure out. So I hope these Steps clarify the process a bit more for future users:

  • Get @UEZs script and save it somewhere
  • Install Core Temp and run it
  • Get the SDK of Core Temp and look in The Folder Path "Shared Memory Framework for Native\Shared Memory Libraries\x64" or "...\x86" for GetCoreTempInfo.dll and copy it to the script location (64-bit or 32-bit)
  • Run Script and enjoy output and modify to your liking

 

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...