start "" "C:\Program Files\program.exe"
我希望只有在没有按键的情况下,程序才能在十分钟后启动。
如果要在十分钟内按任意键,我希望程序不要启动。
我应该在.bat文件中使用哪些命令?
使用以下批处理文件:
@echo off
call :controlTimeout 600
if errorlevel 1 (
echo A key was pressed
) else (
echo Time Up
start "" "C:\Program Files\program.exe"
)
exit /b
:controlTimeout
setlocal
start "" /belownormal /b cmd /q /d /c "timeout.exe %~1 /nobreak > nul"
timeout.exe %~1 & tasklist | find "timeout" >nul
if errorlevel 1 ( set "exitCode=0" ) else (
set "exitCode=1"
taskkill /f /im timeout.exe 2>nul >nul
)
endlocal & exit /b %exitCode%
鸣谢:上面的批处理文件基于StackOverflow答案Windows批处理脚本:捕获用户对MC ND对“超时”命令的反应
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句