JohnOne Posted September 2, 2017 Posted September 2, 2017 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... expandcollapse popup#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.
Gianni Posted September 2, 2017 Posted September 2, 2017 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 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
JohnOne Posted September 2, 2017 Author Posted September 2, 2017 Do you get a believable temp? What OS? I just get 0 now, even with admin of course. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Gianni Posted September 2, 2017 Posted September 2, 2017 without admin I get N/A, with admin I get 55.5 Win7 enterprise x64 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
Gianni Posted September 2, 2017 Posted September 2, 2017 (edited) same temp in a cmd window using this wmic command: wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature /value Edited September 2, 2017 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
careca Posted September 2, 2017 Posted September 2, 2017 I get N/A regardless. and the wmic cmd says "not supported" Its win10x64 Reveal hidden contents 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
UEZ Posted September 2, 2017 Posted September 2, 2017 You can use the SDK from Core Temp to get the CPU temp. This is what I did in 2014: expandcollapse popup#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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Trong Posted September 2, 2017 Posted September 2, 2017 On 9/2/2017 at 11:46 AM, UEZ said: You can use the SDK from Core Temp to get the CPU temp. Expand 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,
JohnOne Posted September 2, 2017 Author Posted September 2, 2017 Thanks guys. Appreciated. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
bolthead Posted September 3, 2017 Posted September 3, 2017 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
MarcElser Posted January 6, 2022 Posted January 6, 2022 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
Developers Jos Posted January 7, 2022 Developers Posted January 7, 2022 @MarcElser, Guess you didn't notice that the thread is +4 years old? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now