@echo off
REM Program : c:\mrc\shutdown\reboot.bat
REM Purpose : This batch file is used to schedule a reboot of an NT server.

:MENU
cls

echo.
echo.
echo                               %COMPUTERNAME% - Reboot Menu
echo                               ~~~~~~~~~~~~~~~~~~~~~
echo.
echo.
echo.
echo                             [1] Schedule a reboot
echo.
echo                             [2] Schedule a WEEKLY reboot
echo.
echo                             [3] Show reboots that are scheduled
echo.
echo                             [4] Delete a Scheduled reboot
echo.
echo                             [5] Exit
echo.
echo.
echo.
c:\mrc\shutdown\choice /C:12345 "Select an option : " 
if errorlevel 5 goto END
if errorlevel 4 goto DELETE
if errorlevel 3 goto SHOW
if errorlevel 2 goto W_REBOOT
if errorlevel 1 goto REBOOT

:REBOOT
set READ=
set STIME=
if exist c:\mrc\shutdown\time.tmp del c:\mrc\shutdown\time.tmp > nul
echo.
echo Enter scheduled reboot time (hh:mm) followed by CNTRL+Z and ENTER
echo.
echo Enter reboot time :
copy con c:\mrc\shutdown\time.tmp > nul
echo.
for /F %%A in (c:\mrc\shutdown\time.tmp) do set STIME=%%A
c:\mrc\shutdown\choice /c:YN "Shutdown server %COMPUTERNAME% at %STIME% "
if errorlevel 2 goto MENU

goto MESSAGE

:NO_CHKDSK
at %STIME% c:\mrc\shutdown\shutdown.bat

:MESSAGE
echo.
if exist c:\mrc\shutdown\time.tmp del c:\mrc\shutdown\time.tmp > nul

echo.
echo IMPORTANT - ENSURE THERE ARE NO CD'S OR FLOPPIES IN THE SERVERS DRIVES BEFORE
echo THE SERVER REBOOTS!  CD'S CAN BE EJECTED REMOTELY IN "MY COMPUTER" IF NEEDED.
echo.
pause
goto SHOW

:W_REBOOT
set READ=
set STIME=
if exist c:\mrc\shutdown\time.tmp del c:\mrc\shutdown\time.tmp > nul
echo.
echo Enter WEEKLY scheduled reboot time (hh:mm) followed by CNTRL+Z and ENTER
echo.
echo Enter WEEKLY reboot time :
copy con c:\mrc\shutdown\time.tmp > nul
echo.
for /F %%A in (c:\mrc\shutdown\time.tmp) do set STIME=%%A

cls
echo.
echo               Select the day of the week to carry out the reboot.
echo               NOTE : The server will reboot on this day at the 
echo               specified time until cancelled.
echo.
echo                             [1] Monday
echo.
echo                             [2] Tuesday
echo.
echo                             [3] Wednesday
echo.
echo                             [4] Thursday
echo.
echo                             [5] Friday
echo.
echo                             [6] Saturday
echo.
echo                             [7] Sunday
echo.
echo                             [8] Exit
echo.
echo.
echo.
c:\mrc\shutdown\choice /C:12345678 "Select the reboot day : " 
if errorlevel 1 set SDAY=M
if errorlevel 2 set SDAY=T
if errorlevel 3 set SDAY=W
if errorlevel 4 set SDAY=TH
if errorlevel 5 set SDAY=F
if errorlevel 6 set SDAY=S
if errorlevel 7 set SDAY=SU
if errorlevel 8 goto MENU

if "%SDAY%"=="M"  set DAY=Monday
if "%SDAY%"=="T"  set DAY=Tuesday
if "%SDAY%"=="W"  set DAY=Wednesday
if "%SDAY%"=="TH" set DAY=Thursday
if "%SDAY%"=="F"  set DAY=Friday
if "%SDAY%"=="S"  set DAY=Saturday
if "%SDAY%"=="SU" set DAY=Sunday

echo.
echo.
c:\mrc\shutdown\choice /c:YN "Shutdown server %COMPUTERNAME% at %STIME% every %DAY% "
if errorlevel 2 goto MENU

goto MESSAGE2

:NO_CHKDSK_W
at %STIME% /every:%SDAY% c:\mrc\shutdown\shutdown.bat

:MESSAGE2
echo.
if exist c:\mrc\shutdown\time.tmp del c:\mrc\shutdown\time.tmp > nul

echo.
echo IMPORTANT - ENSURE THERE ARE NO CD'S OR FLOPPIES IN THE SERVERS DRIVES BEFORE
echo THE SERVER REBOOTS!  CD'S CAN BE EJECTED REMOTELY IN "MY COMPUTER" IF NEEDED.
echo.
pause
goto SHOW

:SHOW
at|find "There are no entries in the list.">nul
if errorlevel 1 goto SHOW_SHUT
echo.
echo.
echo There are no scheduled reboots for server %COMPUTERNAME%
echo.
pause
goto MENU

:SHOW_SHUT
echo.
at
echo.
pause
goto MENU

:DELETE
at|find "There are no entries in the list.">nul
if errorlevel 1 goto DELETE_SHUT
echo.
echo.
echo There are no scheduled reboots for server %COMPUTERNAME%
echo.
pause
goto MENU

:DELETE_SHUT
if exist c:\mrc\shutdown\date.tmp del c:\mrc\shutdown\date.tmp > nul
echo.
at
echo.
echo Enter the ID of the scheduled job to be deleted followed by CNTRL+Z and ENTER
echo.
echo Enter Job ID or ALL :
copy con c:\mrc\shutdown\date.tmp > nul
echo.
for /F %%A in (c:\mrc\shutdown\date.tmp) do set ID=%%A
c:\mrc\shutdown\choice /c:YN "Delete Scheduled job ID:%ID% "
if errorlevel 2 goto MENU

if "%ID%"=="all" goto DEL_ALL
if "%ID%"=="ALL" goto DEL_ALL

at %ID% /delete > nul
goto DEL_MESSAGE

:DEL_ALL
at /delete /yes > nul

:DEL_MESSAGE
echo.
echo.
at|find "There are no entries in the list.">nul
if errorlevel 1 goto SHOW_DEL
echo.
echo.
echo There are no scheduled reboots for server %COMPUTERNAME%
echo.
pause
goto MENU

:SHOW_DEL
echo.
at
echo.
pause
goto MENU

:END
if exist c:\mrc\shutdown\time.tmp del c:\mrc\shutdown\time.tmp > nul
if exist c:\mrc\shutdown\date.tmp del c:\mrc\shutdown\date.tmp > nul
