How to automatically close App_A when I close App_B using batchfile - batch-file

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 :)

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.

I'm not very good using the windows commandline, but I would try the following approach:
start imulator (which should quit automatically after APP_B exited)
start APP_B (using the /wait option - this should pause the batch processing)
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.

Related

How to start a .exe after a specific game closes with a batch file

I have just did this code with a batch file that closes the windows process explorer.exe. It starts some other programs that help with stuttering and closing explorer.exe helps quite a bit.
Thing is to start the game, I need to open a launcher but I want to close the launcher when I start the game. The game is fortnite. In the code it ends explorer.exe but when I close fortnite (Not the launcher), I want explorer.exe to start up.
Code:
START C:\"Program Files (x86)"\"Epic Games"\Launcher\Portal\Binaries\Win32\EpicGamesLauncher.exe
START C:\Users\Yqmxh\Documents\Optimization(s)\TimerResolution.exe
START C:\Users\Yqmxh\Documents\Optimization(s)\"Mz Game Accelerator.lnk"
Taskkill /F /IM explorer.exe
start /wait "C:\Windows\explorer.exe"
exit
I don't know how much cpu time this consumes, but it would work at least:
:beginning
tasklist | FIND "FortniteClient-Win64"
IF NOT %ERRORLEVEL% == 1 (ECHO process was found
ECHO now waiting for six seconds
PING localhost -n 6 >NUL
GOTO beginning
)
ECHO the EXE is not running anymore
explorer
Since I considered the FOR loop too complex, I settled with a GOTO, which I hope I won't get downvoted for ;)
I think it's pretty self-explaining, but feel free to ask, if I'm wrong.

Batch - If an Audio File is Not Playing is it Considered a Task?

I have been working on a project idea today, and I encountered this issue while attempting to kill an audio task. Here's my code (Problem is after the code block):
:two
ECHO Reading...
start C:\Users\Gigabyte\Documents\Audacity\FDD.wav
timeout /t 24 >nul /nobreak
taskkill FDD.wav
GOTO continue
:three
ECHO Reading
start C:\Users\Gigabyte\Documents\Audacity\HDD.wav
Timeout /t 44 >nul /nobreak
taskkill HDD.wav
:continue
It gave me an error that something was invalid then shut the window. I usually am able to read it word by word but time has taken it's toll on me. All I know is that something in quotes is invalid as of right now. However, I have suspicion that the audio file name is invalid and no such task exists. And this goes back to the main question. 'If an Audio File is Not Playing is it Considered a Task?'.
(If it's a matter of task or process ID's then how do I find them?)
(If you need some more code to find out the context of the situation I'll gladly add some)
Audio files are data files, not executables. You need to find the program that is actually playing the audio file and kill it instead. So if you were using Windows Media Player then kill that. (Groove Music not included)
-SomethingDark

Opening 2 programs with a batch file, how can i kill a program AFTER i exit the other program myself?

So i'm unfortunately not a coder (yet, i'll be starting learning windows c++ in a couple of months), and i'd like to understand more how batch files work by doing something like this :
Basically, when i start 2 programs (here, Fortnite and a script alongside) with a selfmade batch file, i'd like the script to be killed ONLY when/after i exit Fortnite.
I've tried 2 methods :
http://prntscr.com/kai6iy (start /wait) -
http://prntscr.com/kai68g (:waitForExit)
Is there something i'm doing wrong? the 1st method just doesn't kill the script when i exit Fortnite, and the 2nd one instantly kills the script in a millisecond, way before Fortnite has even started! :/
I don't know anything windows-related right now! Only started objective-c for mac yet.
You did not provide any output so it is hard to guess, but try adding /t and /f to the taskkill command and see if it helps. I was able to make it work with Notepad and Calculator. If the code below still does not work please be sure to post any errors you are getting. We will need more info.
Your code would be:
#echo off
cd C:\Users\odile\Documents\SCRIPTS
start /b fortnitecp.exe
cd "C:\Program Files\Fortnite\FortniteGame\Binaries\Win64"
start /wait FortniteClient-Win64-Shipping.exe
taskkill /IM fortnitecp.exe /T /F
(I also added quotes around the second path since it has spaces)

Need Batch file help searching for specific string being created in another rolling open session?

Thanks. Thought I'd try writing a batch file to kill another open cmd session that is constantly open churning out lots of scrolling info.
I got a bit carried away and am now outta my league so to speak.
Basically I am trying to search for "£000.00" within a each emerging line of tet that appears in the other running open command window. The running command session is named in the window as C:\windows\system32\cmd.exe but is does have a valid .exe process name in task manager while running and open.
The batch file code below is as far as I've got.
The idea is that when the above string is found in the other process that process/program get closed down them re-launched.
This is as far as I've got.
#echo off
#echo off
title Shut down other process and relaunch
:loop
start /d "C:\Users\Desktop" ActiveDOSprogram.exe
:: #setlocal enabledelayedexpansion
:: #echo off
:: set stringfound=1
find /c "*£000.00*" C:\Windows\system32\cmd.exe && (echo found %date% %time%:~0,-3% >> "%USERPROFILE%\Desktop\Crash_Report.txt"
taskkill /IM ActiveDOSprogram.exe /F
timeout /t 20
start /d "C:\Users\Desktop" ActiveDOSprogram.exe
goto loop
So when I tried this without any variables and in a loop and I think i nearly blew my PC!
Reason I'm stuck is I'm really a novice at this (but trying) and I got as far as I think I need a variable in there somewhere, that only move's to the next line (taskkill+restart) when £000.00 is found in the other process.
Thanks
wingman

Need a little push on my batch script

I am running a batch file that is malicious (for educational reasons) for my school.
What it does is it will repeat and worm and use up space. What i am looking for is to run it and be able to run it in the background so that it wont popup in the foreground. Like me going on facebook and it running in the background not affecting what i am doing. Again, not looking to harm any specific PC with this.
I am very new to batch.
#echo off
:A
SET /A X=%RANDOM%%%1999999999%
type damage.bat >> %x%.bat
start %x%.bat
goto:A
Please help me be able to run this into the background instead of the foreground.
Any help would be appreciated very much!
EDIT:: could you also make it automatically close out all the windows it creates?
First, three things:
%random% outputs a random number from 0 to 32767 (as described in HELP SET) so you don't really need the modulus.
You're allowed to run the same script multiple times, so I wouldn't bother renaming them.
You'll find a few useful parameters in HELP START: /B starts the script in the same window, and /MIN starts in minimized.
So, you get a really simple damage.bat:
#echo off
:a
start /b /min damage.bat
goto :a
Which actually really crashed my computer when I tried it -.-
This keeps the CMD window open, so you might want to add a launchDamage.bat:
#echo off
start /min damage.bat
exit
Which runs damage.bat minimized, then exits -> closes CMD window.
replace this
start %x%.bat
with this
start %x%.bat /min
That should work, but dont want to try to corrupt my computer XD
For info on any comand do
theConfusingComand /?

Resources