ok after abit of more tinkerin ive also found out the :Running wasnt killing the listed processes in it and the threshold being yet still too high for 100% reliability on all apps aka when they take abit longer to load and gpu usage being too low, so tweaked that and ive fixed said non functioning kill process by adding () around the commands also added a starter to the kill process or else it would not work proper aka following processes not being killed at all and even the batch infinite running instead of exiting , this for an app
its also odd the cpu+memory dont work on every app , like it simple exits the batch due to it thinking cpu+mem are below threshold , dont even kill the app if it it truly was so , and yet for an app it works proper , this is my app batch that includes cpu+memory+gpu threshold:
Code: Select all
@echo OFF
Title Autolaunch and Autoexit All Game Processes tied to app
::========= Set cpuThreshold [%] and memThreshold [according to displayed value in Cmd window] =========
set /a cpuThreshold=10 & set /a memThreshold=480000
::initialize vars and set process_name:
set /a low=0 & setlocal enableDelayedExpansion & set process_name=app.exe
set pn=%process_name:.exe=%
::==================================================================
::Launch the App
start "" "app.exe"
TIMEOUT /t 3
tasklist | findstr /i %process_name% > nul && start /min "" "appaddon.exe"
timeout /t 20
cd /D "C:\Program Files\NVIDIA Corporation\NVSMI\"
:GPU
for /f skip^=8^ tokens^=1-3^ delims^=^| %%a in ('"nvidia-smi.exe"') do (
for /f "tokens=1-2 delims= " %%g in ("%%c") do set z=%%g) & goto :breakForLoop
:breakForLoop
set /a z=z & timeout /t 13
if %z% Lss 5 TaskKill /F /im %process_name% & goto RUNNING
::Get NumberOfCores
for /f "tokens=*" %%f in ('wmic cpu get NumberOfCores /value ^| find "="') do set %%f
:CheckCpuAndMem
set /a process_snapshot=0 & set /a memUsg=0
::CPU
for /f skip^=2^ tokens^=3^ delims^=^" %%p in (
'typeperf "\Process(%pn%)\%% Processor Time" -sc 1') do for /f "tokens=1 delims=." %%a in (
"%%p") do set /a process_snapshot=%%a/%NumberOfCores%
if %process_snapshot% LSS %cpuThreshold% (set /a low+=1) else (set /a low=0)
::Mem
for /f "tokens=5" %%p in (
'tasklist ^|findstr %process_name%') do for /f "tokens=1,2,3 delims=." %%a in ("%%p") do set /a memUsg=%%a%%b%%c/1000
if %memUsg% lss %memThreshold% (set /a low+=1) else (set /a low=0)
::echo feedback
@echo process_snapshot: %process_snapshot%, memUsage: %memUsg%; LowCpuAndMem: %low%
::12 checks (Cpu & Mem) times 3 sec timeout plus processing delay yields ca 30 sec
if %low% GEQ 12 taskkill /F /T /IM %process_name% & goto RUNNING
timeout /t 3
tasklist|findstr %process_name% > nul && GOTO GPU
:RUNNING
tasklist|findstr %process_name% > nul && RUNNING
taskkill /F /T /IM WerFault.exe & exit /b
timeout /t 1
GOTO RUNNING
and this works on another app, only gpu threshold , since cpu+memory simple kill batch without touching the app >
Code: Select all
@echo OFF
Title appvk_with_reshade
set VK_LAYER_PATH="" "app;%VK_LAYER_PATH%"
set VK_INSTANCE_LAYERS=VK_LAYER_reshade
@start "" "app.exe"
TIMEOUT /t 20
:: set process_name:
set process_name=app.exe
::=================================================================
:Launch the App
timeout /t 3
tasklist | findstr /i %process_name% > nul && start /min "" "app.ahk"
timeout /t 20
cd /D "C:\Program Files\NVIDIA Corporation\NVSMI\"
:GPU
for /f skip^=8^ tokens^=1-3^ delims^=^| %%a in ('"nvidia-smi.exe"') do (
for /f "tokens=1-2 delims= " %%g in ("%%c") do set z=%%g) & goto :breakForLoop
:breakForLoop
set /a z=z & timeout /t 13
if %z% Lss 10 TaskKill /F /im %process_name% & goto RUNNING
goto GPU
:RUNNING
tasklist|findstr %process_name% > nul && (
taskkill /F /T /IM "WerFault.exe" & exit /b)
timeout /t 1
GOTO RUNNING
also no idea how to integrate both of these functions>
Code: Select all
set process_Wer=WerFault.exe
:Loading
timeout /t 5 & set /a LoadTime= %LoadTime%+5
if %LoadTime% Geq 60 Goto Running
tasklist|findstr %process_name% > nul && Goto Running
Goto Loading
tasklist|findstr %process_Wer% > nul && Goto Terminate
:Terminate
taskkill /F /T /IM "WerFault.exe"
what is also interesting of a find is for one app a gpu threshold of 10 works proper , but for another a threshold of 5 works and with 10 quickly exits