Conditional shutdown batch file

Submitted by admin on

Advanced Windows batch example : Conditional shutdown


@echo off
color 0A
title Conditional Shutdown

:start
echo What would you like to do?
echo.
echo 1. Shutdown in specified time
echo 2. Shutdown now
echo 3. Restart now
echo 4. Log off now
echo 5. Hibernate now
echo.
echo 0. Quit
echo.

set /p choice="Enter your choice: "
if %choice%==1 goto shutdown
if %choice%==2 shutdown -s -f
if %choice%==3 shutdown -r -f
if %choice%==4 shutdown -l -f
if %choice%==5 shutdown -h -f
if %choice%==0 exit
echo Invalid choice: %choice%
echo.
pause
cls
goto start

:shutdown
cls
set /p sec="Minutes until shutdown: "
set /a min=60*%sec%
shutdown -s -f -t %min%
echo Shutdown initiated at %time%
echo.
set /p cancel="Type cancel to stop shutdown "
if %cancel%==cancel shutdown -a
if %cancel%==cancel cls
if %cancel%==cancel echo Shutdown is cancelled.
if %cancel%==cancel echo.
if %cancel%==cancel pause
if %cancel%==cancel exit