1

Batch

@echo off
:loop
(tasklist /fi "IMAGENAME eq RocketLeague.exe"| findstr /I "RocketLeague.exe")>nul|| taskkill /f /im BakkesMod.exe
timeout /t 2
goto :loop

The attached batch file checks if a certain program (R) is running; if that program (R) is not running, it will kill another program (B). how can I make the batch file executing the command (in this case start, not taskkill) once when the program (R) is running instead?

3
  • I think you can use some code in the fashion per this answer I wrote; adjust and use accordingly: superuser.com/questions/993129/batch-file-troubles-in-windows-7/… Oct 1 at 13:47
  • thanks! ...and (using your script) how can I make it prompting to the ELSE when also another program is running? (the two programs must run together to make it pass, otherwise it's another error like the ERRORLEVEL 1) Oct 1 at 15:01
  • I want to make it running commands when two programs are working simultaneously, not only one -just by this way, if only one of the two programs is working it should be considered like an error Oct 1 at 15:06

3 Answers 3

0

Use && instead of ||. The definitions are :

  • && executes the second command only if the previous command's errorlevel is 0

  • || executes the second command only if previous command's errorlevel is NOT 0

2
  • thanks! ...and (using his script, superuser.com/questions/993129/batch-file-troubles-in-windows-7/…) how can I make it prompting to the ELSE when also another program is running? (the two programs must run together to make it pass, otherwise it's another error like the ERRORLEVEL 1) Oct 1 at 15:02
  • I want to make it running commands when two programs are working simultaneously, not only one -just by this way, if only one of the two programs is working it should be considered like an error Oct 1 at 15:04
0

Here's some batch code that may give you a better starting point. If this doesn't work 100% for exactly what you need, it may be close enough so you can make it work.

Rather than having routines use GOTO :EOF it's just be a trivial matter tell which routine to GOTO :CheckRisRunning to start the process from the beginning again if both processes are running.

The same is true with the timeout and adding it beneath the call command before the next call if you need the 2 second delay after starting one process before starting the other or anywhere else in the logic—just trivial adjustments to figure out how exactly you need it to work.

Essentially this...

  • Checks if RocketLeague.exe is running in memory

    • If not it goes to the :StartB routine
    • If so, it sets a counter variable with a count of 1 and goes to :CheckBisRunning routine
  • The :CheckBisRunning routine checks if BakkesMod.exe is running in memory

    • If not it goes to the :StartB routine
    • If so, it adds 1 to the counter variable and goes to the :CheckCount routine
  • The :CheckCount routine checks if the count variable is equal to 2

    • If not, it goes to the :StartB routine
  • The :StartB routine kills all instances of both RocketLeague.exe and BakkesMod.exe running in memory, waits 2 seconds, and then starts RocketLeague.exe followed by starting BakkesMod.exe again so both are started

Batch

@ECHO OFF

:CheckRisRunning
SET /A "c=0"
TASKLIST | FINDSTR /I "RocketLeague.exe"
IF ERRORLEVEL 1 (GOTO :StartB) ELSE (SET /A "c+=1" & GOTO :CheckBisRunning)
GOTO :EOF

:CheckBisRunning
TASKLIST | FINDSTR /I "BakkesMod.exe"
IF ERRORLEVEL 1 (GOTO :StartB) ELSE (SET /A "c+=1" & GOTO :CheckCount)
GOTO :EOF

:CheckCount
if NOT %c%==2 GOTO :StartB
timeout /t 2
GOTO :CheckRisRunning

:StartB
taskkill /f /im "RocketLeague.exe"
taskkill /f /im "BakkesMod.exe"
timeout /t 2
Start "" "C:\Folder\Path\RocketLeague.exe"
timeout /t 2
Start "" "C:\Folder\Path\BakkesMod.exe"
GOTO :CheckRisRunning

Supporting Resources

0

Batch

@echo off

:checkifRocketLeagueisrunning
SET /A "c=0"
TASKLIST | FINDSTR /I "RocketLeague.exe"
IF ERRORLEVEL 1 (SET /A "c+=3" & GOTO addtocount) ELSE (SET /A "c+=1" & GOTO checkifBakkesModisrunning)

:addtocount
SET /A "c+=3"
GOTO checkcount1

:checkcount1
IF %c%==6 (GOTO killBakkesMod) ELSE (SET /A "c=0" & GOTO loopredirect1)

:killBakkesMod
TASKKILL /F /IM BakkesMod.exe
SET /A "c=0"
GOTO checkifRocketLeagueisrunning

:loopredirect1
GOTO checkifRocketLeagueisrunning

:checkifBakkesModisrunning
TASKLIST | FINDSTR /I "BakkesMod.exe"
IF ERRORLEVEL 1 (SET /A "c+=1" & GOTO checkcount2) ELSE (SET /A "c=0" & GOTO loopredirect2)

:loopredirect2
GOTO checkifRocketLeagueisrunning

:checkcount2
IF %c%==2 (GOTO startBakkesMod) ELSE (SET /A "c=0" & GOTO loopredirect3)

:loopredirect3
GOTO checkifRocketLeagueisrunning

:startBakkesMod
START "" "%USERPROFILE%\AppData\Roaming\bakkesmod\bakkesmod\BakkesMod.exe"
SET /A "c=0"
GOTO checkifRocketLeagueisrunning


thanks so much for helping me! finally I solved it by myself also thanks to your advice (code attached above). I converted the batch to an application using Advanced BAT to EXE Converter, so here it is the direct link to download the setup file, since this app can be useful to all Epic Games Rocket League PC players because it automates the BakkesMod process when playing Rocket League (BakkesMod will start automatically when Rocket League starts and will stop automatically when Rocket League stops).



when downloading Setup.exe

maybe your PC will recognise this setup as a virus, but actually it's a false-positive, for real!, I would never share a virus. if your PC detects it as a virus, please select 'Keep' to keep the file when it's being downloaded, deactivate your own antivirus, then try to open it and, if your PC blocks it again, open Windows Defender and choose 'Allow' for every related-threat recognised. after that, if you can't find the setup anymore, re-download it. when you open it, you have to click on 'More info' and then choose 'Run anyway'. When the setup process is done, you can delete Setup.exe.



before starting BakkesModprocessautomation.exe

in order to make it works, you must have all the BakkesMod main files (BakkesMod.exe, unins000.exe, unins000.dat) located in this folder, %USERPROFILE%\AppData\Roaming\bakkesmod\bakkesmod, because also this software will work there. it's already configured to run at the PC startup, so you won't have to do anything with it after the installation. when you'll start it, it will be invisible, will run forever in background and can only be stopped manually through Task Manager (by killing BakkesModprocessautomation.exe) or via commands (like 'taskkill /f /im BakkesModprocessautomation.exe').

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.