我的问题是当按下右上角的X来执行名为exit.exe的文件时,如何制作批处理脚本而不是关闭。
答案 0 :(得分:5)
这个问题有几点不够明确:
<强> starter.bat:强>
@echo off
echo Start yourScript.bat:
start "" /W yourScript.bat
echo Value returned from the script: %errorlevel%
if %errorlevel% neq 12345 ECHO execute exit.exe
<强> yourScript.bat:强>
@echo off
echo I am the script.bat
set /P var=input value:
rem Terminate normally:
exit 12345
答案 1 :(得分:3)
[X]是&#34;遥不可及&#34;为cmd
。唯一可以想到的方法是:创建另一个cmd
来观察当前窗口的存在:
@echo off
title WatchMe
more +7 %~f0 >t2.bat
start "watcher" t2.bat
exit /b
@echo off
:running
tasklist /v|find "WatchMe" >nul &&echo waiting || goto finished
timeout 1 >nul
goto running
:finished
echo "the process has finished