【发布时间】:2013-12-20 16:37:43
【问题描述】:
我想编写一个简单的批处理脚本来关闭我自己的计算机,当我在床上看 DVD 或其他东西时将使用它。
更新:修复了代码,还有其他建议吗?
setlocal
@echo off & break off
:input
set /p "minutes=Enter number of minutes to wait until shutdown: "
set "numcheck="&for /f "delims=0123456789" %%i in ("%minutes%") do set "numcheck=%%i"""
if defined numcheck (
echo ERROR: Sorry "%minutes%" is not numeric, please try again & echo.
goto input
)
if %minutes% gtr 315360000 (
echo ERROR: Sorry your input is greater then 10 years, I can't handle that & echo.
goto input
)
set /a "seconds=%minutes%*60"
shutdown.exe /s /f /t "%seconds%"
if errorlevel 1 (
echo ERROR: Could not set shutdown, try again & echo.
goto input
)
:abort
set /p "continue=Your computer is about to shutdown in %minutes% minutes, do you want to abort? (yes/no): "
if %continue% equ yes (
echo Aborting...
shutdown.exe /a
if errorlevel 1 (
echo ERROR: Could not stop shutdown, try again & echo.
goto abort
)
timeout.exe /t 5 /NOBREAK
endlocal
exit /b
) else (
timeout.exe /t 10 /NOBREAK
endlocal
exit /b
)
【问题讨论】:
-
您是否收到错误,或者为什么它不起作用?
-
我在此处发布 1 分钟后自己修复了它。大声笑,无论如何我会更新上面的代码,也许你们还有其他建议;)
-
你遇到了什么错误?
-
&&用于检查错误级别。&分隔命令。 -
thx foxidrive,我更新了代码
标签: windows batch-file windows-8 shutdown