如何使批处理文件等待进程开始,然后继续?

Eri*_*ham 4 windows batch command-line

有人能告诉我需要在 [X] 中写什么才能使 Maplestory.exe 进程在启动时被杀死吗?我不想使用定时命令,谢谢!(运行的gamelauncher.exe原因maplestory.exe

@echo off
start D:\Games\MapleStory\GameLauncher.exe
[X]
taskkill /im MapleStory.exe
exit

nhi*_*kle 6

我会将输出从tasklistinto输入管道find,搜索maplestory,并使用IF语句和 aGOTO继续循环,检查该进程,直到找到为止。一旦找到,那么你就可以GOTO通过不同的点来杀死任务。

像这样的事情应该可以解决问题:

:search
tasklist|find "maple"
IF %ERRORLEVEL% == 0 GOTO :found
TIMEOUT /T 1
GOTO :search

:found
taskkill /im maplestory.exe
Run Code Online (Sandbox Code Playgroud)

(该TIMEOUT命令将脚本暂停 1 秒。这将有助于防止它在不断运行该循环时占用过多 CPU。)