Page 1 of 1

ProgramA closes and ProgramB closes automatically

Posted: 11 Sep 2019 13:22
by Vikiller94
Hello,

I would like that Batch automatically close ProgramB (Syncprogram) before I close ProgramA (Minecraft)

Here is my code:

Code: Select all

@echo off

start "" "C:\Users\Viktor\Documents\FreeFileSync Auftraege\RealTimeSync Auftraege\RealTime_(.minecraft-GoogleDrive)_[Mirror].ffs_real"

start "" "C:\Users\Viktor\Documents\FreeFileSync Auftraege\RealTimeSync Auftraege\RealTime_(.minecraft-Backupfolder)_[Mirror].ffs_real"

timeout 3 >nul

start "" "C:\Program Files (x86)\Minecraft\MinecraftLauncher.exe"

:MAIN

tasklist /fi "imagename eq MinecraftLauncher.exe"
if not '%ERRORLEVEL%'=='0' goto DEAD

goto MAIN

:DEAD
taskkill /f /im RealTimeSync_x64.exe

exit

The problem is it does not work.

My idea was to place a loop with :Main. If Minecraft still running the Sync program does not close because it jumps up and repeats until Minecraft closes. When it closes it will be redirected to :DEAD and the sync close.

Can anyone help me with that?

Re: ProgramA closes and ProgramB closes automatically

Posted: 11 Sep 2019 16:59
by aGerman
I would like that Batch automatically close ProgramB (Syncprogram) before I close ProgramA (Minecraft)
Don't get it. How should a program ever know that a human is about to close A in order to close B programmatically in advance?

Steffen

Re: ProgramA closes and ProgramB closes automatically

Posted: 12 Sep 2019 05:00
by Vikiller94
Look I created this code:

Code: Select all

 @echo off
start "" "C:\Users\Viktor\Documents\FreeFileSync Auftraege\RealTimeSync Auftraege\RealTime_(.minecraft-GoogleDrive)_[Mirror].ffs_real"
start "" "C:\Users\Viktor\Documents\FreeFileSync Auftraege\RealTimeSync Auftraege\RealTime_(.minecraft-Backupfolder)_[Mirror].ffs_real"
start "" "C:\Program Files (x86)\Minecraft\MinecraftLauncher.exe"

:Active
tasklist /v | find "MinecraftLauncher.exe"
if errorlevel == 0 goto Dead
goto Active

:Dead
taskkill /FI /IM "RealTimeSync_x64.exe"

pause

Re: ProgramA closes and ProgramB closes automatically

Posted: 12 Sep 2019 11:13
by Aacini
Try:

Code: Select all

@echo off
start "" "C:\Users\Viktor\Documents\FreeFileSync Auftraege\RealTimeSync Auftraege\RealTime_(.minecraft-GoogleDrive)_[Mirror].ffs_real"
start "" "C:\Users\Viktor\Documents\FreeFileSync Auftraege\RealTimeSync Auftraege\RealTime_(.minecraft-Backupfolder)_[Mirror].ffs_real"

( start "" "C:\Program Files (x86)\Minecraft\MinecraftLauncher.exe" ) | pause

taskkill /FI /IM "RealTimeSync_x64.exe"

pause
For an explanation of this method, see this answer.

Antonio