0

Hi everyone I'm a newbie in batchfiling but loved tinkering and coding every other time. Can I make a batch file that closes two program simultaneously? Example, I created a batchfile that opens two program, App_A (gamepad imulator) is minimized App_B (offline RPG Game) normal window. What I want is when I close App_B App_A would automatically close too so that I don't have to restore the window and manually close the imulator.

this is the code I just did which I also found in this site and got it working:

ECHO OFF
start /d "C:\Documents and Settings\Computer\My Documents\Imulator\PROFILE" SET1.imulatorprofile /m
ECHO IMULATOR STARTED
start /d "C:\Program Files\App_B" App_BLauncher.exe
ECHO APP_B STARTED
ECHO OPERATION COMPLETE

Any comments or suggestions is GREATLY APPRECIATED! THANKS in ADVANCE :)

2 Answers2

0

I'm not very good using the windows commandline, but I would try the following approach:

  1. start imulator (which should quit automatically after APP_B exited)
  2. start APP_B (using the /wait option - this should pause the batch processing)
  3. kill imulator (using PsKill by name)

You can find details about start, PsKill and other commands at this site.

Hope that helps a bit.

*Jost


...added later...

Another option would be to do regular checks in the background if a process (App_B) is running and continue (with stopping App_A) when it is finished. This approach makes sense when App_B is only a launcher for another process (e.g. App_Launched_By_B) and comes back directly.

This can be done with a small loop which might look similar to this one:

start "App_A" /d "C:\Programs\App_A" App_A.exe
ECHO App_A STARTED
start "App_B" /d "C:\Programs\App_B" App_B.exe
ECHO App_B STARTED

ECHO GIVE App_B 30 SECONDS TO LAUNCH App_Launched_By_B 
SLEEP 30

:LOOP
PSLIST App_Launched_By_B >nul 2>&1
IF ERRORLEVEL 1 (
  GOTO CONTINUE
) ELSE (
  ECHO App_Launched_By_B IS STILL RUNNING - PAUSE ANOTHER 5 SECS
  SLEEP 5
  GOTO LOOP
)

:CONTINUE
PsKill App_A
ECHO App_A STOPPED

This example came originally from another answer and was written by aphoria. I adapted it just a little little bit for this case.

Additional information about PsList and other commands can be found at this site.

I also want to note that I do not really like this approach, because it consumes some cpu without doing much. But it is the only solution from a batch file I can see.

Community
  • 1
  • 1
Jost
  • 1,549
  • 12
  • 18
  • thnks Jost gotta try this and post a feedback. :) – Jao Laoreno Jul 16 '13 at 08:26
  • nice! the taskkill is working but I don't know where should I put the taskkill and the /wait option. – Jao Laoreno Jul 16 '13 at 09:28
  • maybe I need to add other syntax: `echo off start "skyrim Launcher" /d "C:\Documents and Settings\YourComputer\My Documents\xpadder_gamepad_profiler\PROFILE" SKYRIM.xpadderprofile ECHO XPADDER STARTED start /wait /d "C:\Program Files\Skyrim Legendary Edition" SkyrimLauncher.exe taskkill /f /im Xpadder.exe /wait` when I do this the /wait option on the last line the emulator exits early so I can't use it in the game. when I put it before the taskkill option I still have to manually close it. T__T – Jao Laoreno Jul 16 '13 at 09:43
  • ok - I see that your **App_B** it is only a launcher which comes a back directly - so the wait is not working. I attached a second option which might help a bit better. – Jost Jul 16 '13 at 10:28
  • Whew! Finally! After researching, reading, brainstorming, and having a headache. The working code is your first comment Jost, haha. The reason why it isn't working is that the game launcher (App_B) is a launcher of a launcher (confusing?) which has options: PLAY SETTINGS SUPPORT EXIT. So when I click the PLAY option the "wait" syntax is used, that's why the emulator(App_A) exits prematurely. – Jao Laoreno Jul 18 '13 at 06:19
  • I found another launcher on the game.exe directory folder and used it which launches the game directly without the options. I did your first suggested code with the "wait" syntax on the App_B and it WORKED PERFECTLY as what I wanted it to be. This is the code `echo off` `start "App_A" /d "C:\My Documents\Folder" App_A.exe` `ECHO APP_A STARTED` `start /W /d "C:\Program Files\Game" App_B.exe` `ECHO APP_B STARTED` `taskkill /f /im Xpadder.exe` Thanks guys for helping out and for sharing links. I want to leave a rating but don't have enough rep T__T. Thanks again and God bless.^_^ – Jao Laoreno Jul 18 '13 at 06:31
  • and sorry for not having the correct markdown editing. haven't learned it yet.T__T – Jao Laoreno Jul 18 '13 at 06:59
0

You can use another batch file with two taskkill lines, one for each of your apps, and launch that.

Otherwise you'd need to have a batch file running all the time in a window, which loops and checks if appB is not running and then it will close appA. It's not very elegant.

foxidrive
  • 40,353
  • 10
  • 53
  • 68