Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal EnableDelayedExpansion
- rem Initialize and go to start
- set title=Shutdown Later
- set version=2.0
- set splash1= %title% v%version%
- set splash2= UI by KubosKube
- title %splash1%
- set preset1= 1m
- set preset2= 2m
- set preset3= 3m
- set preset4= 5m
- set preset5=10m
- set preset6=20m
- set preset7=30m
- set preset8= 1h
- set preset9= 2h
- set preset10= 3h
- goto :start
- rem Splash Text
- :splash
- echo %splash1%
- echo %splash2%
- echo %splash3%
- goto :eof
- rem Display options
- :start
- cls
- echo.
- echo ! WORK IN PROGRESS !
- echo.
- call :splash
- echo.
- echo Choose a preset time offset, or provide your own timestamp and offset.
- echo 1 ............ %preset1%
- echo 2 ............ %preset2%
- echo 3 ............ %preset3%
- echo 4 ............ %preset4%
- echo 5 ............ %preset5%
- echo 6 ............ %preset6%
- echo 7 ............ %preset7%
- echo 8 ............ %preset8%
- echo 9 ............ %preset9%
- echo 10 ........... %preset10%
- echo.
- echo +01:30:00 .... shutdown in 1h30m
- echo 01:30:00 ..... shutdown at 1:30am
- echo.
- echo help ......... Show examples of how to use non-preset times.
- echo changelog .... Show changes from previous versions to current version.
- echo.
- echo.
- echo Enter a preset number or a custom input...
- set /p input=
- if not defined input goto :start
- if %input% == changelog goto :changelog
- if %input% == help goto :help
- rem Early jump to Custom Input
- if not %input% == %input:+=% goto :custom
- rem Check for Preset input
- set loop=10
- :inputLoop
- if %input% EQU %loop% goto presets
- set /a loop-=1
- if %loop% GTR 0 goto inputLoop
- rem No preset given, go to Custom Input
- goto :custom
- rem Parse Preset Inputs
- :presets
- call :debug "Preset input provided"
- if %input% EQU 1 set /a offset=1*60
- if %input% EQU 2 set /a offset=2*60
- if %input% EQU 3 set /a offset=3*60
- if %input% EQU 4 set /a offset=5*60
- if %input% EQU 5 set /a offset=10*60
- if %input% EQU 6 set /a offset=20*60
- if %input% EQU 7 set /a offset=30*60
- if %input% EQU 8 set /a offset=1*60*60
- if %input% EQU 9 set /a offset=2*60*60
- if %input% EQU 10 set /a offset=3*60*60
- goto :execute
- rem Parse Custom Input
- :custom
- call :debug "Custom input provided"
- if %input% == %input:+=% (
- call :debug "Mode: timestamp"
- set time_set=%input%
- ) else (
- call :debug "Mode: offset"
- set time_offset=%input:*+=%
- call set "time_set=%%input:+!time_offset!=%%"
- )
- call :debug "input = %input% time_set = %time_set% time_offset = %time_offset%"
- if defined time_set (
- call :debug "Entering timestamp calculations"
- call :tokenize %time_set%
- for /f "tokens=1-3" %%a in ("!tokens!") do ( set hours=00%%a& set minutes=00%%b& set seconds=00%%c)
- set time_stamp=!hours:~-2!:!minutes:~-2!:!seconds:~-2!
- call :debug "Time Stamp = !time_stamp!"
- call :convertTime %time%
- set /a time_now=!convertedTime! + 0
- call :convertTime !time_stamp!
- set /a time_then=!convertedTime! + 0
- set /a "time_delta=(!time_then!-!time_now!) + 0"
- call :debug "time_now = !time_now! time_then = !time_then! time_delta = !time_delta!"
- if !time_delta! LSS 0 (
- set /a "time_delta= !time_delta! + (1*24*60*60)"
- call :debug "Corrected time_delta = !time_delta!"
- )
- )
- call :debug "This line is just before time_offset calculations. time_offset = %time_offset%"
- if defined time_offset (
- call :debug "Entering timestamp calculations"
- call :tokenize +%time_offset%
- for /f "tokens=1-4" %%a in ("!tokens!") do ( set /a days=%%d + 0& set /a hours=%%c + 0& set /a minutes=%%b + 0& set /a seconds=%%a + 0 )
- set offset_nominal=!days! days, !hours! hours, !minutes! minutes, !seconds! seconds
- call :debug "Offset = !offset_nominal!"
- call :debug "about to run the command: set /a offset_in_seconds=((!days! * 24 * 60 * 60) + (!hours! * 60 * 60) + (!minutes! * 60) + !seconds!)"
- set /a offset_in_seconds=((!days! * 24 * 60 * 60) + (!hours! * 60 * 60) + (!minutes! * 60) + !seconds!)
- call :debug "offset_in_seconds = !offset_in_seconds!"
- )
- call :debug "this line is immediate after offset calculations"
- if not defined time_delta set time_delta=0
- if not defined offset_in_seconds set offset_in_seconds=0
- set /a "time_to_wait_in_seconds=(%time_delta% + %offset_in_seconds%)"
- call :debug "adding time_delta %time_delta% with %offset_in_seconds% to get total wait time %time_to_wait_in_seconds%"
- goto :execute
- call :error "Oops, something seems to have gone catestrophically and horrendously insanely wrong. Try again?"
- rem This will likely never ever happen right here, but just in case the code pointer escapes, here's a shortcut to the end.
- goto :eof
- rem Tokenize Argument
- :tokenize
- for /f "tokens=1-4 delims=:." %%a in ("%1") do ( set tokens=%%a %%b %%c %%d )
- call :debug "Tokenize %1 -> %tokens%"
- if not "!tokens!" == "!tokens:+=!" (
- call :debug "'!tokens!' not equal to '!tokens:+=!'"
- set reverse=
- for %%a in (!tokens!) do (
- set reverse=%%a !reverse!
- shift
- )
- set tokens=!reverse:+=!
- call :debug "Reversed tokens for offset use. %1 -> !tokens!"
- )
- goto :eof
- rem Time Format -> Seconds
- :convertTime
- for /f "tokens=1-3 delims=:.," %%a in ("%1") do (
- call :debug "Converting Time: arg1 %%1 deliminated a %%a b %%b c %%c"
- set /a "convertedTime=((%%a * 60 * 60) + (%%b * 60) + %%c)"
- )
- call :debug "Convert Time %1 -> %convertedTime%"
- goto :eof
- rem Debug
- :debug
- echo.
- echo %1
- echo.
- pause
- goto :eof
- rem Error Reporter
- :error
- echo.
- echo.
- echo error
- echo %1
- echo.
- echo.
- pause
- goto :start
- rem Execution of Shut Down
- :execute
- cls
- echo.
- call :splash
- echo.
- call :debug "Entering Execution. Adding timestamp %timestamp% and %offset_in_seconds% to get total wait time %time_to_wait_in_seconds%"
- echo Shutting down in %time_to_wait_in_seconds% seconds
- :: echo such as %time_stamp% and %offset_nominal%
- echo.
- echo Closing this window will interrupt the process safely.
- echo Have a nice day!
- echo.
- timeout %time_to_wait_in_seconds% /nobreak
- ::if defined offset shutdown /s /t 5
- echo That totally worked.
- pause
- goto :eof
- rem Help
- :help
- cls
- echo.
- call :splash
- echo.
- echo -----
- echo.
- echo This script can understand two types of custom input.
- echo.
- echo "Set" Time
- echo and
- echo "Offset" Time
- echo.
- echo It differentiates between the two based on the presense/location of a "+" symbol.
- echo.
- echo A custom input of "12:00:00" will translate to 12:00pm.
- echo A custom input of "+12:00:00" will translate to mean twelve hours from time of input.
- echo.
- echo Both can be used together.
- echo.
- echo A custom input of "12:00:00+12:00:00" will translate to
- echo Twelve hours after 12:00pm.
- echo.
- echo.
- echo page 1 / 5
- echo.
- pause
- echo -----
- echo.
- echo Colons can be replaced with Decimals freely.
- echo This is to make entry on the 10-key Number Pad easier.
- echo.
- echo Also, the number of digits is not monitored.
- echo.
- echo For example, the following custom inputs would all be parsed identically:
- echo.
- echo 12:00:00
- echo 12.00.00
- echo.
- echo 12:00000:00
- echo 12.0.0
- echo.
- echo.
- echo page 2 / 5
- echo.
- pause
- echo -----
- echo.
- echo For "Set" Time, the hours and minutes are required.
- echo If you do not include a placeholder for seconds, it will be assumed to be zero.
- echo.
- echo The following two examples are parsed identically:
- echo.
- echo 12:00:00
- echo 12:00
- echo.
- echo.
- echo page 3 / 5
- echo.
- pause
- echo -----
- echo.
- echo For "Offset" Time, parsing assumes you input seconds, and builds up from there.
- echo "Offset" Time also can accept up to a number of days to delay for.
- echo.
- echo The following table shows a handful of inputs and their effect to demonstrate these points.
- echo.
- echo +30 ........... plus 30 seconds
- echo +1:30 ......... plus 1 minute 30 seconds
- echo +1:30:00 ...... plus 1 hour 30 minutes
- echo +1:00:00:00 ... plus 1 day
- echo.
- echo.
- echo page 4 / 5
- echo.
- pause
- echo -----
- echo.
- echo This script only has limited error handling.
- echo.
- echo Always double-check the final screen after input shows the correct value.
- echo.
- echo.
- echo page 5 / 5
- echo.
- echo Continuing now will lead back to the main menu.
- echo.
- pause
- goto :start
- rem Changelog
- :changelog
- cls
- echo.
- call :splash
- echo.
- echo v2.0
- echo + Re-made UI
- echo + Added ability to shut down at a set time
- echo + Added splash text to every screen
- echo + Added a help menu
- echo + Added a changelog
- echo.
- echo - Removed the entirety of v1.0
- echo.
- echo.
- echo v1.0
- echo + Added the ability to shut down after a delay
- echo.
- pause
- goto :start
- :: You've made it to the end of the document, congratulations.
- :: Please tell me about my redundant remarks next to every label.
Advertisement
Add Comment
Please, Sign In to add comment