关机倒计时

时间:2016-08-12 00:25:55

标签: batch-file

@echo off
:start
set /p INPUT=Would you like to shutdown your computer in 5 seconds? (Y/N) 
If /i "%INPUT%" == "y" goto yes
If /i "%INPUT%" == "n" goto no

:yes
timeout /t 1 >nul 2>&1
echo Shutting down in 5
timeout /t 1 >nul 2>&1
echo Shutting down in 4
timeout /t 1 >nul 2>&1
echo Shutting down in 3
timeout /t 1 >nul 2>&1
echo Shutting down in 2
timeout /t 1 >nul 2>&1
echo Shutting down in 1
timeout /t 1 >nul 2>&1
shutdown /h

:no
exit

当我运行时,我尝试关闭我的电脑。我打字' y'然后按Enter键,它会重定向到代码的开头。有没有办法来解决这个问题? ('是的'下没有goto命令。但是':没有'工作。)

1 个答案:

答案 0 :(得分:-1)

只需将您的批处理文件重命名为 shutdown.bat ,然后就可以了!

你的问题与Why does the ping command in my batch file execute in a loop

类似

记住这一点:

请勿使用与现有程序相同的名称命名您的bat文件。

关机倒计时 (Shutdown /h)以休眠计算机!

@echo off
Title Countdown to shutdown
Mode con Cols=65 lines=4 & Color 0A
set /a num=5
:start
echo(
set /p "INPUT=Would you like to shutdown your computer in 5 seconds ? (Y/N) " 
If /i "%INPUT%" == "y" goto CountDown
If /i "%INPUT%" == "n" goto no
Exit /b

:CountDown
cls
echo(
echo Process and Services will be automatically stop after %num% seconds..
Timeout /T 1 /NoBreak >nul
set /a num=num-1
if %num% GTR -1 goto :CountDown
goto shutdown

:no
exit

:Shutdown
Rem (Shutdown /h) to hibernate the computer !
shutdown /h

编辑于2016年8月12日@ 10:17倒计时关闭计数

@echo off
Title Countdown for shutdown
Mode con Cols=65 lines=4 & Color 0A
set /a num=5
:start
echo(
echo  Would you like to shutdown your computer in 5 seconds ? (Y/N) ?
Call:Speak "Would you like to shutdown your computer in 5 seconds ?" 
set /p "INPUT="

If /i "%INPUT%" == "y" goto yes
If /i "%INPUT%" == "n" goto no
Exit /b

:yes
cls
echo(
echo Process and Services will be automatically stop after %num% seconds..
Call:Speak "Process and Services will be automatically stop after %num% seconds.."
Goto Countdown

:CountDown
cls
echo(
echo Process and Services will be automatically stop after %num% seconds..
Call:Speak "%num% !"
Timeout /T 1 /NoBreak >nul
set /a num=num-1
if %num% GTR -1 goto :CountDown
goto shutdown

:no
exit

:Speak <msg>
(
    echo Set sapi=Createobject("sapi.spvoice"^)
    echo sapi.Speak("%~1"^)
)>"%tmp%\%~n0.vbs"
Cscript /nologo "%tmp%\%~n0.vbs"
Del "%tmp%\%~n0.vbs"
exit /b

:Shutdown
Call:Speak "We Shutdown the computer !" 
shutdown /h