Well, So I am trying to automate starting a game with a trainer, mostly to see if I could, however, I have run into an annoyance and was curious if anyone could figure out why...for me... or help me =)
The issue: setup works great with a test setup, and not at all with the desired setup.
What i think it may be: I believe, the 'call' function in the batch, in the test setup it runs the "called" bat and waits for it to finish before proceeding, in the desired setup, it runs the "called" batch but continues on without waiting for it to finish.
My setups:
-Test: run a game trainer (first exe file), wait a sec, call batch that runs testMC.exe (is minecraft...) when testMC.exe(javaw.exe) closes batch continues back to first batch and closes trainer then exits.
-Desired: run the trainer, wait, call batch to run game (darksouls), darksouls exits,etc(as above)
As i stated per my issue, it just runs right through the called batch file, running the game but not the code in the called batch, thusly closing the trainer and finish the batch while the game is still open.
My batch files:
First or launcher
and the called bat that waits for the game to close
So, to clarify what I am trying to do.
1. I want to start a trainer.exe
2. wait for it to load
3. call a batch that starts the game
3a. (loop) check if the game is running
3b. when game is not running, 2nd batch finishes, back to finish first batch
4. close trainer
5. exit
Thank you all for any insight.
P.S. Darksouls runs as DARKSOULS.exe and DATA.exe, I've tried both as _progname neither work. MC runs as javaw.exe, so it starts with a dif exe but i cant see that effecting this process.
EDIT: Also, the batch that checks if the game is still running works just fine.
A link to a text log, LOG
The issue: setup works great with a test setup, and not at all with the desired setup.
What i think it may be: I believe, the 'call' function in the batch, in the test setup it runs the "called" bat and waits for it to finish before proceeding, in the desired setup, it runs the "called" batch but continues on without waiting for it to finish.
My setups:
-Test: run a game trainer (first exe file), wait a sec, call batch that runs testMC.exe (is minecraft...) when testMC.exe(javaw.exe) closes batch continues back to first batch and closes trainer then exits.
-Desired: run the trainer, wait, call batch to run game (darksouls), darksouls exits,etc(as above)
As i stated per my issue, it just runs right through the called batch file, running the game but not the code in the called batch, thusly closing the trainer and finish the batch while the game is still open.
My batch files:
First or launcher
CSS:
@echo off
:start
title Darksouls w/ trainer
set game=Darksouls
start trainer.exe || goto error
ping 1.1.1.1 -n 1 -w 1000 > nul
echo.
echo.
echo (%date%)(%time%) %game% is now running
echo Waiting for %game% to close...
call called
taskkill /f /im trainer.exe
goto close
:error
echo error
echo.
echo.
echo.
echo.
echo Failed to start
echo.
SET "A="
SET /P A=Do you wish to (1)exit or (2)retry:
ECHO Waiting for selection .........
IF "%A%"=="1" exit
IF "%A%"=="2" goto start
:close
exit
and the called bat that waits for the game to close
CSS:
@Echo Off
Set _ChkInt=10
Set _MaxWait=60000
Set _ProgName=DARKSOULS.exe
Set _ImgName=DARKSOULS.exe
Call :_FixName "%_ImgName%"
Set /A _PWait=_ChkInt*1000
Set _TotalWait=0
Start "" "%_ProgName%"
:WaitLoop
Ping 1.0.0.0 -n 1 -w %_PWait%>Nul
Set /a _TotalWait+=_ChkInt
If %_TotalWait% GEQ %_MaxWait% Goto Continue
tasklist /NH /FI "IMAGENAME eq %_ImgName%" 2>Nul|Find /I "%_ImgName%">Nul
If %ERRORLEVEL%==0 Goto WaitLoop
:Continue
Echo Waited %_TotalWait% Seconds Or %_ProgName% Exited
::Pause
Goto :EOF
:_FixName
Set _ImgName=%~nx1
Goto :EOF
So, to clarify what I am trying to do.
1. I want to start a trainer.exe
2. wait for it to load
3. call a batch that starts the game
3a. (loop) check if the game is running
3b. when game is not running, 2nd batch finishes, back to finish first batch
4. close trainer
5. exit
Thank you all for any insight.
P.S. Darksouls runs as DARKSOULS.exe and DATA.exe, I've tried both as _progname neither work. MC runs as javaw.exe, so it starts with a dif exe but i cant see that effecting this process.
EDIT: Also, the batch that checks if the game is still running works just fine.
A link to a text log, LOG