Appropriate way polling of events without timeout.exe

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Posts: 2
Joined: 11 Aug 2022 14:22

Appropriate way polling of events without timeout.exe

#1 Post by betapolling » 11 Aug 2022 20:19

I have the following script which is a fail-safe because all my other attempts to lower the system temperature don't give me the temperatures I need. Change fan, thermal paste, add external fan, thoroughly clean dust etc in my old laptop, which is burn the old GPU back in a day. The GPU is changed, the HDD is now an SSD and add a internal USB3 expresscard.

Temperatures will read by OpenHardwareMonitorReport which need some more files/libraries from OpenHardwareMonitor.
OpenHardwareMonitorReport is a console application able to produce hardware text reports. The official OpenHardwareMonitor, the SpeedFan and some other tools I test like wmic does not have the ability to shutdown or to execute some other external executable and/or does not read my GPU or CPU sensors.

I notice timeout.exe with help from procexp.exe with admin rights.
Is there is a way to polling for events without timeout.exe? The event in my case is some high temperature value when the CPU and/or GPU are in high load. Any other tool/suggestion or script optimization are welcome.

Code: Select all

rem Because OpenHardwareMonitorReport needs elevated permissions this batch is suppose to start by elevate.exe from
rem in user's Startup shortcut like this: C:\Windows\System32\elevate.exe D:\ohmr\RingABellWhenTempIsHigh.cmd
rem so then the console title of this batch will not be RingABellWhenTempIsHigh.cmd as usual but will be c:\windows\system32\cmd.exe
rem D:\ohmr directory will also hold the whole OpenHardwareMonitorReport application and this batch script.
rem Nircmd.exe needs to be in c:\windows eg. start nircmd.exe without parameters and allow it to "install".

rem Change the console title anyway and hide that console.
TITLE RingABellWhenTempIsHigh.cmd
nircmd.exe win hide ititle "RingABellWhenTempIsHigh.cmd"

rem Set the temporary file variable which will hold the OpenHardwareMonitorReport's results data.
set temperature_results=%temp%\RingABellWhenTempIsHigh_OpenHardwareMonitorReport.tmp

rem Nircmd or maybe cmd, has trouble to execute an exe by these elevated rights if the exe has absolute path in front of it
rem so go to the directory OpenHardwareMonitorReport.exe resides in eg. D:\ohmr to avoid the absolute path issue.
cd /d "%~dp0"

rem Set a random number which will be used to hold log files that will stay to the disk between shutdowns.
set r=%random%

rem Script initialization finised, begin an infinite loop.
rem In case system just starting, wait 60 seconds anyway between loop iterations.
timeout /t 60 /nobreak >nul

rem Make a hardware report in temperature_results file and hide the OpenHardwareMonitorReport console
nircmd.exe exec hide OpenHardwareMonitorReport.exe reporttofile -f %temperature_results% --IgnoreMonitorFanController --IgnoreMonitorHDD --IgnoreMonitorMainboard --IgnoreMonitorRAM

rem Wait OpenHardwareMonitorReport.exe to finish.
nircmd.exe waitprocess OpenHardwareMonitorReport.exe
rem The above is more precise than "timeout /t 5 /nobreak >nul"

rem Get temperatures from cpu and gpu sensors. Tested on 2 core intel cpu with nvidia gpu.
rem Don't know if the search strings are the same on amd, ati, radeon or intel gpu system.
FOR /F "tokens=8" %%i in ('findstr /e /l /c:"cpu/0/temperature/0)" %temperature_results%^|findstr /b /l /c:"|  +- CPU Core #1    :"') do set cputemp0=%%i
FOR /F "tokens=8" %%i in ('findstr /e /l /c:"cpu/0/temperature/1)" %temperature_results%^|findstr /b /l /c:"|  +- CPU Core #2    :"') do set cputemp1=%%i
FOR /F "tokens=7" %%i in ('findstr /e /l /c:"gpu/0/temperature/0)" %temperature_results%') do set gputemp=%%i

rem Find the maximum temperature and set it to maxt.
set maxt=%cputemp0%
if %cputemp0% LSS %cputemp1% set maxt=%cputemp1%
if %maxt% LSS %gputemp% set maxt=%gputemp%

rem If maxt is above 88 degrees celsius write temperatures log, initiate a shutdown, make a tasklist log using the random number and exit.
if %maxt% GTR 88 echo cpu0:%cputemp0% cpu1:%cputemp1% gpu:%gputemp% temperature at shutdown:%maxt% > %temp%\shutdown_temp_%r%.log
rem Use encoding from a text editor only in this warning message bellow, if it is in another language in order to appear as sould be in the system shutdown dialog.
if %maxt% GTR 88 shutdown /s /c "Warning system temperature above 88 degrees."
if %maxt% GTR 88 tasklist > %temp%\shutdown_tasklist_%r%.log
if %maxt% GTR 88 exit

rem Set the volume to maximum if maxt is above 82 and speak about it.
if %maxt% GTR 82 nircmd.exe setvolume 0 65535 65535
if %maxt% GTR 82 nircmd.exe speak text "i'm getting hot" -2 100

rem Make a penetrating sound at 86 degrees.
if %maxt% GTR 86 nircmd.exe beep 2600 3000
goto :begin

Post Reply