ProgramA closes and ProgramB closes automatically

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Vikiller94
Posts: 2
Joined: 11 Sep 2019 13:17

ProgramA closes and ProgramB closes automatically

#1 Post by Vikiller94 » 11 Sep 2019 13:22

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?

aGerman
Expert
Posts: 3753
Joined: 22 Jan 2010 18:01
Location: Germany

Re: ProgramA closes and ProgramB closes automatically

#2 Post by aGerman » 11 Sep 2019 16:59

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

Vikiller94
Posts: 2
Joined: 11 Sep 2019 13:17

Re: ProgramA closes and ProgramB closes automatically

#3 Post by Vikiller94 » 12 Sep 2019 05:00

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

Aacini
Expert
Posts: 1617
Joined: 06 Dec 2011 22:15
Location: México City, México

Re: ProgramA closes and ProgramB closes automatically

#4 Post by Aacini » 12 Sep 2019 11:13

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

Post Reply