Question

How to make this BATch file have a timer? Would like to see how much time left. Windows only says "Windows will shut down in less then a minute".

@echo off
color 0A
title Restart\/Shutdown

:start
echo Welcome, %USERNAME%
echo What would you like to do?
echo.
echo 1. Shut down
echo 2. Restart
echo. 
echo 0. Quit
echo.

set /p choice="Enter your choice: "
if "%choice%"=="1" goto shutdown
if "%choice%"=="2" goto restart
if "%choice%"=="0" exit
echo Invalid choice: %choice%
echo.
pause
cls
goto start

:shutdown
shutdown.exe -s -t 10

:restart
shutdown.exe -r -t 10
Was it helpful?

Solution

You could use the command "timeout /t 10" or something like:

@ECHO OFF
FOR /L %%# IN (10,-1,1) DO (SET/P "=%%# seconds left... "<NUL:
    PING -n 2 127.0.0.1 >NUL
    CLS:)

OTHER TIPS

@ECHO off
cls
color 0B
:taskkill
echo.
echo.
echo.
echo.
echo.               
echo.               
echo.               
echo.               
echo.               
echo.
echo                                Program To Shutdown
echo.
set /p taskkill=                               
if "%taskkill%" == "%taskkill%" goto taskkillconfirm
exit
:taskkillconfirm
color 0B
:image
set image=/im
if "%image%" == "%image%" goto imageconfirm
exit
:imageconfirm
color 0B
:forced
set forced=/f
if "%forced%" == "%forced%" goto forcedconfirm
exit
:forcedconfirm
:hour
color 0B
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.                                   Hours?:
echo.
set /p hour=                                      
:min
color 0B
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo                                   Minutes?:
echo.
set /p min=                                      
:sec
color 0B
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo                                   Seconds?:
echo.
set /p sec=                                      
:continue
color 0B
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo                           %taskkill%  Shutdown in
echo.                                                             
echo                         %hour%  Hours  %min%  Minutes  %sec%  Seconds
set /a sec="%sec%-1"
if %sec%==-1 set /a min="%min%-1"
if %sec%==-1 set /a sec="59"
if %min%==-1 set /a hour="%hour%-1"
if %min%==-1 set /a min="59"
if %hour%==-1 goto done
ping -n 2 127.0.0.1 >NUL
goto continue
:done
color 0B
cls
taskkill %image% %taskkill% %forced%
exit

" ping localhost -n 10 >nul " take off quotations and to edit the amount of seconds replace the 10 with whatever you

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top