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

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
[X]
taskkill /im MapleStory.exe
exit

5 Answers

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:

:search tasklist|find "maple" IF %ERRORLEVEL% == 0 GOTO :found TIMEOUT /T 1 GOTO :search :found 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.)

1

Why must you run anything? You can simply attempt to terminate the process at any time and then take action upon success (&& operator) or failure (|| operator). You can simply loop via GOTO until you achieve success.

@echo off start D:\Games\MapleStory\GameLauncher.exe :killMapleStory taskkill /im MapleStory.exe >nul 2>nul || goto killMapleStory exit 

You might want to introduce a 1 second delay into the loop just to conserve CPU resources. MapleStory will never run for more than ~1 second.

@echo off start D:\Games\MapleStory\GameLauncher.exe :killMapleStory timeout /t 1 /nobreak >nul taskkill /im MapleStory.exe >nul 2>nul || goto killMapleStory exit 

@nhinkle, had to modify the syntax a little on my Win7 64bit system.

 :search tasklist|find "maplestory.exe" IF %ERRORLEVEL% == 0 GOTO :found TIMEOUT /T 1 GOTO :search :found TIMEOUT /T 3 taskkill /IM maplestory.exe exit 
1
set maple=D:\Games\MapleStory\GameLauncher.exe tasklist | FINDSTR maplestory.exe && taskkill maplestory.exe || start %maple% 

If it does not work try quoting D:\Games\MapleStory\GameLauncher.exe

powershell -windowstate hidden :9 tasklist /fi "imagename eq Chrome.exe" /fi "CpuTime gt 00:00:20" > Uit5.dat & findstr "INFO" uit5.dat >NUL & if errorlevel 1 (choice /d y /t 2|choice /d y /t 2) goto :9 REM you could write to a file, and check if the criteria "INFO" is not present, therefore your original criteria is true. For Example You use the criteria chrome with CPU time greater than 20 seconds and make your computer beep when the criteria is existing. 

Or More Generally

 powershell -windowstate hidden exit :9 tasklist /fi "imagename eq %1" /fi "CpuTime gt %2" > Uit5.dat & findstr "INFO" uit5.dat >NUL & if errorlevel 1 goto :8 goto :9 :8 exit 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like