Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

Ask gaming related questions
User avatar
tobsto occupied
Posts: 140
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

27 Aug 2020, 08:45

tobsto occupied wrote:
20 Aug 2020, 07:20
this would be the solution i found

https://stackoverflow.com/questions/57100015/how-do-i-run-nvidia-smi-on-windows

Make a shortcut that runs nvidia-smi and refreshes periodically

Follow the above steps under 'To find your exact location'.
Right click on nvidia-smi.exe (it may just say nvidia-smi in the viewpane) and choose create a shortcut. It will likely tell you that you can't create a shortcut here, and ask if you want to put it on your desktop. Hit yes.
Now, on the desktop, right click on the shortcut you have just created, hit properties, and Under Shortcut > Target modify the string path to include -l < time you want it to refresh >.
For example, modify:

C:\Windows\System32\DriverStore\FileRepository\nvdm*\nvidia-smi.exe
to

C:\Windows\System32\DriverStore\FileRepository\nvdm*\nvidia-smi.exe -l 5
Then hit "Apply", and then "OK".

In this example, when you open the shortcut, it will keep the command prompt open and allow you to watch your work as nvidia-smi refreshes every five seconds.
as explained
User avatar
tobsto occupied
Posts: 140
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

27 Aug 2020, 08:47

this being the shortcut:

"C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe" -l 5
User avatar
rommmcek
Posts: 1123
Joined: 15 Aug 2014, 15:18

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

27 Aug 2020, 09:33

For me change dir works without quotes despite space in the path. Maybe this is the problem for you. I Edited the last script on previous page. Try it and report.
And of corse you still have to determine thresholds for values when game is running vs game is crashed.
User avatar
tobsto occupied
Posts: 140
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

28 Aug 2020, 07:04

rommmcek wrote:
25 Aug 2020, 20:10
Here is extraction code for the data. It works for me (code for me in the spoiler).
You have to determine if the data provide some usable info when the game works vs. game crashes. Then we can take action...

Code: Select all

@echo OFF
cd "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-6 delims= " %%g in ("%%a") do set u=%%g & set v=%%h) & set w=%%j) & (
    for /f "tokens=1-3 delims= " %%g in ("%%b") do set x=%%g & set y=%%i) & (
    for /f "tokens=1-2 delims= " %%g in ("%%c") do set z=%%g) & goto :breakForLoop
:breakForLoop
rem set /a u+=0 & set /a v+=0 & set /a w+=0 & set /a x+=0 & set /a z+=0
set /a u=u & set /a v=v & set /a w=w & set /a x=x & set /a z=z
echo %u%, %v%, %w%, %x%, %y%, %z%
rem pause
timeout /t 5
goto GPU
[Edit] Added quotes to cd command and changed skip to 8 (I think you didn't post complete pic of GPU info.
Spoiler
the pic ive posted actually is the complete cmd window my dude :problem: , ill try that out and ignore the spoiler tagged one i recon
User avatar
tobsto occupied
Posts: 140
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

28 Aug 2020, 07:09

nope still getting same nvidia-smi.exe is not recognized as internal or external command
User avatar
tobsto occupied
Posts: 140
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

28 Aug 2020, 07:14

ok figured it out had to run the batch on the C Drive , been executing it from D,now it dont throw an error...odd
User avatar
tobsto occupied
Posts: 140
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

28 Aug 2020, 07:25

ok fixed it with abit of research you gotta add the /D switch to the cd line as such :

cd /D "C:\Program Files\NVIDIA Corporation\NVSMI\"

that way you can run the batch from any drive and itll work instead of throwing an error
User avatar
tobsto occupied
Posts: 140
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

28 Aug 2020, 07:30

ok so yeah the very last output is the gpu usage right after the VRAM output , so works , itll show no usage from the game once it freezes since theres no rendering being done anymore logically aka the best solution for a freeze monitor , cpu+memory had way too fluctuating variations , but with gpu usage monitoring its deadset either there is rendering or there isnt , and once any game freezes rendering usage stops of course except for whatever else apps you using use gpu rendering in the background such as browser etc which you have to account for in the threshold logically , anyhow so now what?

p.s: thank god for nvidia-smi.exe !!! without it said function would be pretty difficult to implement , theres hope yet :dance:
Last edited by tobsto occupied on 28 Aug 2020, 08:30, edited 1 time in total.
User avatar
tobsto occupied
Posts: 140
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

28 Aug 2020, 08:24

btw on a sidenote found out that some games just get killed regardless if theyre running or not this is an example batchfile i used on a few games, the games mentioned use texmod and thus without texmod running they instant exit, heres for one :
@echo OFF
::initialize vars and set process_name:
set /a low=0 & setlocal enableDelayedExpansion & set process_name=DMC-DevilMayCry.exe
set pn=%process_name:.exe=%
::==================================================================
::Launch the App
start "" "Texmod and Game Autolauncher.exe"
TIMEOUT /t 30
RUNNING
tasklist|findstr DMC-DevilMayCry.exe > nul && (
taskkill /F /T /IM Texmod.exe) & taskkill /F /T /IM Werfault.exe & exit /b
timeout /t 1
GOTO RUNNING
----------------------------------------

not sure whats going on since this happens only on a few games and games are running i even set a timer of 30 seconds where the game is already in the menu , so it apparently happens to ones that dont have nul
if errorlevel 1 ? or nul &&? compatibility ?
User avatar
rommmcek
Posts: 1123
Joined: 15 Aug 2014, 15:18

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

29 Aug 2020, 06:49

The last script you posted has at least one obvious bug (there is no 'real' label). Should be:

Code: Select all

@echo OFF
 ::initialize vars and set process_name:
 set /a low=0 & setlocal enableDelayedExpansion & set process_name=DMC-DevilMayCry.exe
 set pn=%process_name:.exe=%
 ::==================================================================
 ::Launch the App
 start "" "Texmod and Game Autolauncher.exe"
 TIMEOUT /t 30
 :RUNNING
 tasklist|findstr DMC-DevilMayCry.exe > nul && (
 taskkill /F /T /IM Texmod.exe) & taskkill /F /T /IM Werfault.exe & exit /b
 timeout /t 1
 GOTO RUNNING
However this would not solve your problem, instead ti would kill every game as soon it'll get loaded (provided you specify correct process name).
The only condition you have in the script is if process exists in the task list then kill it. So it doesn't make any sense!
When do you really want the process to be killed? At low memory usage? At low CPU usage? Or both? You have already enough examples!
User avatar
rommmcek
Posts: 1123
Joined: 15 Aug 2014, 15:18

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

29 Aug 2020, 07:09

About GPU and Nvidia we are technically finished! You have only to adapt the script to run correctly for you and add the desired condition for killing crashed process.

I don't know for sure from your report wich data is relevant for you. I assume it is 4874MiB (referring to your snapshot)
Besides compare my snapshot versus your snapshot. Every line after command line counts. My snapshot's first line is time stamp then top of the frame and then The name of GPU card and Driver version, etc...
Relevant data start at line 9. That's why we skip first 8 lines. You should adapt the script accordingly for you!
The result should be: 41, 52, 181, 4874, 11264, 66 - referring again to your snapshot.
User avatar
tobsto occupied
Posts: 140
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

30 Aug 2020, 12:48

thanks man shall check it out and get back atcha
User avatar
tobsto occupied
Posts: 140
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

30 Aug 2020, 12:51

rommmcek wrote:
29 Aug 2020, 06:49
The last script you posted has at least one obvious bug (there is no 'real' label). Should be:

Code: Select all

@echo OFF
 ::initialize vars and set process_name:
 set /a low=0 & setlocal enableDelayedExpansion & set process_name=DMC-DevilMayCry.exe
 set pn=%process_name:.exe=%
 ::==================================================================
 ::Launch the App
 start "" "Texmod and Game Autolauncher.exe"
 TIMEOUT /t 30
 :RUNNING
 tasklist|findstr DMC-DevilMayCry.exe > nul && (
 taskkill /F /T /IM Texmod.exe) & taskkill /F /T /IM Werfault.exe & exit /b
 timeout /t 1
 GOTO RUNNING
However this would not solve your problem, instead ti would kill every game as soon it'll get loaded (provided you specify correct process name).
The only condition you have in the script is if process exists in the task list then kill it. So it doesn't make any sense!
When do you really want the process to be killed? At low memory usage? At low CPU usage? Or both? You have already enough examples!
uhhhh no, its supposed to kill Texmod and Werfault ...which happens sometimes, once game exits not the game on startup
User avatar
rommmcek
Posts: 1123
Joined: 15 Aug 2014, 15:18

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

31 Aug 2020, 12:35

rommmcek wrote:
29 Aug 2020, 06:49
The only condition you have in the script is if process exists in the task list then kill it.
Sorry, correct is: The only condition you have in the script is if DMC-DevilMayCry.exe exists in the task list then kill Texmod.exe and Werfault.exe. If this is what you want then the script should work.
User avatar
tobsto occupied
Posts: 140
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

01 Sep 2020, 18:16

shall try thanks and ill get back atcha as said...just been abit busy sorry
User avatar
tobsto occupied
Posts: 140
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

04 Sep 2020, 18:51

rommmcek wrote:
31 Aug 2020, 12:35
rommmcek wrote:
29 Aug 2020, 06:49
The only condition you have in the script is if process exists in the task list then kill it.
Sorry, correct is: The only condition you have in the script is if DMC-DevilMayCry.exe exists in the task list then kill Texmod.exe and Werfault.exe. If this is what you want then the script should work.
yeah well tried your latest version , this>

Code: Select all

@echo OFF
 ::initialize vars and set process_name:
 set /a low=0 & setlocal enableDelayedExpansion & set process_name=DMC-DevilMayCry.exe
 set pn=%process_name:.exe=%
 ::==================================================================
 ::Launch the App
 start "" "Texmod and Game Autolauncher.exe"
 TIMEOUT /t 30
 :RUNNING
 tasklist|findstr DMC-DevilMayCry.exe > nul && (
 taskkill /F /T /IM Texmod.exe) & taskkill /F /T /IM Werfault.exe & exit /b
 timeout /t 1
 GOTO RUNNING
--------------------------------------------




but no success, still instant exit of game due to texmod being instant exited as said thats how games work that use texmod without it they instant exit and for some reason with that game the Errorlevel 0 or 1 apparently isnt it since the batch thinks the game isnt running anymore even tho it is aka the batch cant detect the games running or exit state , ive noticed this with using this command instead as well >

Code: Select all

@echo OFF
 ::initialize vars and set process_name:
 set /a low=0 & setlocal enableDelayedExpansion & set process_name=DMC-DevilMayCry.exe
 set pn=%process_name:.exe=%
 ::==================================================================
 ::Launch the App
 start "" "Texmod and Game Autolauncher.exe"
 TIMEOUT /t 30
 :RUNNING
 tasklist|findstr DMC-DevilMayCry.exe > nul
if errorlevel 1 (
    timeout /t 1
    taskkill /F /T /IM Texmod.exe
    taskkill /F /T /IM Werfault.exe
) & GOTO ENDLOOP
timeout /t 1
GOTO RUNNING
[Mod edit: Codeboxes added.]
---------------------------------------------------------------------------------


...maybe it needs a better checking method?
i mean i do have a solution to this tbh ...but its fucking frankenhack as shit lols it involves using a portable install of the restart app and some vbs and batch files working altogether to use the advanced detection mechanisms of the restart app and that executing said vbs and batch files ...sure ..it works but its convoluted as all hell lols
Last edited by tobsto occupied on 04 Sep 2020, 19:19, edited 1 time in total.
User avatar
tobsto occupied
Posts: 140
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

04 Sep 2020, 19:03

rommmcek wrote:
29 Aug 2020, 07:09
About GPU and Nvidia we are technically finished! You have only to adapt the script to run correctly for you and add the desired condition for killing crashed process.

I don't know for sure from your report wich data is relevant for you. I assume it is 4874MiB (referring to your snapshot)
Besides compare my snapshot versus your snapshot. Every line after command line counts. My snapshot's first line is time stamp then top of the frame and then The name of GPU card and Driver version, etc...
Relevant data start at line 9. That's why we skip first 8 lines. You should adapt the script accordingly for you!
The result should be: 41, 52, 181, 4874, 11264, 66 - referring again to your snapshot.
uhhh...still confused and yes the results should be as youve posted>

The result should be: 41, 52, 181, 4874, 11264, 66 - referring again to your snapshot.
------------------------
would you have a actual batch that i could try lols ...seriously have no freakin idea how to implement with this noob mind of mine lmfao :crazy: :think:

heres an example bat from the mem+cpu batch one i use for doom , which we both know is kinda shit since cpu+mem fluctuates way too randomly for it to be of any use hence the gpu core usage solution instead >

Code: Select all

@echo OFF
set VK_LAYER_PATH="" "DOOM;%VK_LAYER_PATH%"
set VK_INSTANCE_LAYERS=VK_LAYER_reshade
@start "" "DOOMx64vk.exe" +devMode_Enable 1 +com_restarted 1 +com_gameMode 1 +com_skipIntroVideo 1 +exec DOOMConfig.cfg 1 +image_usecompression 0 +com_skipKeyPressOnLoadScreens 1
TIMEOUT /t 20
::========= Set cpuThreshold [%] and memThreshold [according to displayed value in Cmd window] =========
set /a cpuThreshold=17        & set /a memThreshold=450000
::initialize vars                            and set process_name:
set /a low=0 & setlocal enableDelayedExpansion & set process_name=DOOMx64vk.exe
set pn=%process_name:.exe=%
::==================================================================
::Launch the App
tasklist | findstr /i %process_name% > nul && start /min "" "easy access to campaign.ahk"
::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 CheckCpuAndMem
:RUNNING
tasklist|findstr %process_name% > nul && (
    taskkill /F /T /IM cheatengine-x86_64.exe) & taskkill /F /T /IM Werfault.exe & exit /b
timeout /t 1
GOTO RUNNING
[Mod edit: Codebox added.]
User avatar
rommmcek
Posts: 1123
Joined: 15 Aug 2014, 15:18

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

06 Sep 2020, 10:52

tobsto occupied wrote:
30 Aug 2020, 12:51
uhhhh no, its supposed to kill Texmod and Werfault ...which happens sometimes, once game exits not the game on startup
Oh, sorry again, superficial reading! Hope "game exits" is right (not "game crashes"). Try:

Code: Select all

. . .
TIMEOUT /t 30
:RUNNING
 timeout /t 5
 tasklist|findstr DMC-DevilMayCry.exe > nul && Goto RUNNING
 taskkill /F /T /IM Texmod.exe & taskkill /F /T /IM Werfault.exe & exit /b
P.s.: Have increased timeout to check every 5 sec. O.k.? Then be sure TIMEOUT /t 30
is long enough to load the game, otherwise script will trigger the TaskKill routine and exit!
User avatar
rommmcek
Posts: 1123
Joined: 15 Aug 2014, 15:18

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

06 Sep 2020, 11:05

For GPU first just run the code:

Code: Select all

@echo OFF
cd /D "C:\Program Files\NVIDIA Corporation\NVSMI\"
:GPU
for /f skip^=6^ tokens^=1-3^ delims^=^| %%a in ('"nvidia-smi.exe"') do (
    for /f "tokens=1-6 delims= " %%g in ("%%a") do set u=%%g & set v=%%h) & set w=%%j) & (
    for /f "tokens=1-3 delims= " %%g in ("%%b") do set x=%%g & set y=%%i) & (
    for /f "tokens=1-2 delims= " %%g in ("%%c") do set z=%%g) & goto :breakForLoop
:breakForLoop
rem set /a u+=0 & set /a v+=0 & set /a w+=0 & set /a x+=0 & set /a z+=0
set /a u=u & set /a v=v & set /a w=w & set /a x=x & set /a z=z
echo %u%, %v%, %w%, %x%, %y%, %z%
rem pause
timeout /t 5
goto GPU
If the periodical output isn't something like: 41, 52, 181, 4874, 11264, 66, then repeat it with skip^=7^ and so on. Then you can set the condition.
P.s.: I still don't know for sure wich variable is relevant (Probably 4874 for your previous snapshot output)!

Return to “Gaming”

Who is online

Users browsing this forum: gtr and 16 guests