当另一个结束批处理时结束一个过程

时间:2015-06-05 02:02:48

标签: batch-file taskkill

我有Oddworld Abe的Oddysey,但游戏对我的GamePad效果不佳所以我不得不使用Joy2Key,我创建了一个.bat来启动这两个进程,但它不能正常工作。

我希望当我停止玩游戏时,使JoyToKey.exe进程结束,但我无法使用我的代码,我该怎么办?

start JoyToKey_en\JoyToKey.exe
start /wait AbeWin.exe
taskkill /f /im JoyToKey.exe

2 个答案:

答案 0 :(得分:0)

这个示例向您展示如何检查(AcroRd32.exe)(Adobe Reader)之类的进程是否正在运行,因此如果未运行该脚本,请尝试启动它当然你可以在陈述之后杀死它!

@echo off
Title Check process for starting
mode con cols=65 lines=5 & color 9B
Set ProcessPath=%ProgramFiles%\Adobe\Reader 11.0\Reader
set ProcessName=AcroRd32.exe
Tasklist /nh /fi "imagename eq %ProcessName%" | find /i "%ProcessName%" >nul && (
    echo %ProcessName% is started
) || (
    echo %ProcessName% is not started & Start "" "%ProcessPath%\%ProcessName%"
) 
pause
Echo Killing %ProcessName%
Taskkill /IM "%ProcessName%" /F
pause

此批次带有菜单:

@Echo off & cls & color 0B
Mode con cols=72 lines=10
Set TmpFile=TmpFile.txt
Set Resultat=KillResult.txt
If Exist %TmpFile% Del %TmpFile%
If Exist %Resultat% Del %Resultat%
:menuLOOP
Cls & color 0B
Title Process Starter and Killer by Hackoo 2015
echo.
echo.      ==========================Menu============================
echo.
for /f "tokens=1,2,* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do echo.           %%B  %%C
echo.
echo.      ==========================================================
set choice=
echo. & set /p choice=Make a choice or hit ENTER to quit: || GOTO :EOF
echo. & call :menu_%choice%
GOTO:menuLOOP
::********************************************************************************************
:menu_1 StartMyProcess
cls & color 0B
echo.
Set /p "MyProcess=Enter the process name  "
echo.
echo The process %MyProcess% is started ... 
Start %MyProcess%
GOTO :menuLOOP
::********************************************************************************************
:menu_2 KillProcess
Title Process Killer by Hackoo 2015
cls & color 0B
echo.
echo                What process do you want to kill ?
echo.
set/p "process=Enter the name of the process> "
cls & color 0C
Title Killing "%process%" ...
echo.
echo                       Killing "%process%" ...
echo.
echo %date% *** %time% >> %TmpFile%
For %%a in (%process%) Do Call :KillMyProcess %%a
Cmd /U /C Type %TmpFile% > %Resultat%
Start %Resultat%
GOTO :menuLOOP
::*********************************************************************************************
:KillMyProcess
Taskkill /IM "%~1" /F >> %TmpFile% 2>&1
echo ***************************************************************************** >> %TmpFile%
exit /b 
::*********************************************************************************************
:EOF
EXIT

答案 1 :(得分:0)

你的代码应该工作检查脚本日志,删除@echo关闭(如果你有)并在最后放一个停顿看看它吐出的错误,你不知道如何解决问题然后发布一个如果我能看到什么是错误的控制台的照片和病态

[编辑]

尝试这个我测试过,如果它仍然不起作用,它会显示控制台

start JoyToKey_en\JoyToKey.exe
echo n | start /wait AbeWin.exe
taskkill /f /im JoyToKey.exe