@echo off
color 0A
title Conditional Shutdown.
 
:MAIN 
cls
ECHO.
ECHO ...............................................
ECHO PRESS 1, 2 OR 3 to select your task, or 4 to EXIT.
ECHO ...............................................
ECHO.
ECHO 1 - Open Notepad
ECHO 2 - Open Calculator
ECHO 3 - Open Notepad AND Calculator
ECHO 4 - For loop
ECHO 5 - EXIT
ECHO. 
ECHO.0 GOTO NEXT MENU
echo.

SET /P M=Type 1, 2, 3, 4 or 0 then press ENTER : 
IF %M%==1 GOTO NOTE
IF %M%==2 GOTO CALC
IF %M%==3 GOTO BOTH
IF %M%==4 GOTO forLoop
IF %M%==5 GOTO EOF
IF %M%==0 GOTO start


:NOTE
cd %windir%\system32\notepad.exe
start notepad.exe
GOTO MAIN

:CALC
cd %windir%\system32\calc.exe
start calc.exe
GOTO MAIN

:BOTH
cd %windir%\system32\notepad.exe
start notepad.exe
cd %windir%\system32\calc.exe
start calc.exe
GOTO MAIN

:forLoop
cls
echo Welcome to a for loop example
@echo off &setlocal enabledelayedexpansion
for /L %%x in (1, 1, 10) do (
    SET /a VAR=%%x %% 5
    set /a CAL=!VAR! %% 5
    echo %%x MOD 5 = !CAL!
)

pause

@echo off &setlocal enabledelayedexpansion
echo.
echo Display even numbers only
for /L %%x in (0, 2, 10) do (
    SET /a VAR=%%x %% 5
    set /a CAL=!VAR! %% 5
    echo %%x MOD 5 = !CAL!
)

pause

@echo off &setlocal enabledelayedexpansion
echo.
echo Display odd numbers only
for /L %%x in (1, 2, 10) do (
    SET /a VAR=%%x %% 5
    set /a CAL=!VAR! %% 5
    echo %%x MOD 5 = !CAL!
)

pause

GOTO MAIN
 
:start
cls
echo Welcome, %USERNAME%
echo What would you like to do?
echo.
echo 1. Shutdown in specified time
echo 2. Shutdown at a specified time
echo 3. Shutdown now
echo 4. Restart now
echo 5. Log off now
echo 6. Hibernate now
echo. 
echo 0. Quit
echo.
echo 9 GOTO MAIN MENU
 
set /p choice="Enter your choice: "
if "%choice%"=="1" goto shutdown
if "%choice%"=="2" goto shutdown-clock
if "%choice%"=="3" shutdown.exe -s -f
if "%choice%"=="4" shutdown.exe -r -f
if "%choice%"=="5" shutdown.exe -l -f
if "%choice%"=="6" shutdown.exe -h -f
if "%choice%"=="0" GOTO EOF
if "%choice%"=="9" goto MAIN



echo Invalid choice: %choice%
echo.
pause
cls
goto start
 
:shutdown
cls
set /p min="Minutes until shutdown: "
set /a sec=60*%min%
shutdown.exe -s -f -t %sec%
echo Shutdown initiated at %time%
echo.
goto cancel
 
:shutdown-clock
echo.
echo the time format is HH:MM:SS (24 hour time)
echo example: 14:30:00 for 2:30 PM
echo.
set /p tmg=enter the time that you wish the computer to shutdown on: 
schtasks.exe /create /sc ONCE /tn shutdown /st %tmg% /tr "shutdown.exe -s -t 00"
echo shutdown initiated at %tmg%
echo.
 
:cancel
set /p cancel="Type cancel to stop shutdown: "
if not "%cancel%"=="cancel" exit
shutdown.exe -a
cls
schtasks.exe /end /tn shutdown
cls
schtasks.exe /delete /tn shutdown
cls
echo Shutdown is cancelled.
echo.
pause
exit

:EOF
cls
@echo off
echo.
echo.
echo Sample program has ended. Thank you
