Windows – How to make a batch file wait for a process to begin, then continue

batchcommand linewindows

Can someone tell me what do I need to write in [X] to make the process Maplestory.exe be killed when it will start? I don't want to use timing commands, thanks! (the gamelauncher.exe causes the maplestory.exe to run)

@echo off
start D:\Games\MapleStory\GameLauncher.exe
taskkill /im MapleStory.exe

Best Answer

I would pipe the output from tasklist into find, search for maplestory, and use an IF statement and a GOTO to continue looping, checking for that process, until it's found. Once it's found, then you can GOTO a different point to kill the task.

Something like this should do the trick:

tasklist|find "maple"
IF %ERRORLEVEL% == 0 GOTO :found
GOTO :search

taskkill /im maplestory.exe

(The TIMEOUT command pauses the script for 1 second. This will help prevent it from sucking up too much CPU constantly running that loop.)