I really liked your question, I thought it was very interesting so I decided to investigate and try it, this was the code I made from what I found:
@echo off
SET HOUR=%time:~0,2%
IF "%hour:~0,1%" == " " SET HOUR=0%HOUR:~1,1%
SET MIN=%time:~3,2%
IF "%min:~0,1%" == " " SET MIN=0%MIN:~1,1%
SET SECS=%time:~6,2%
IF "%secs:~0,1%" == " " SET SECS=0%SECS:~1,1%
SET TIME_TO_SHOW=%HOUR%:%MIN%:%SECS%
SET TIME_TO_VALIDATE=%HOUR%%MIN%%SECS%
SET SECONDS_TO_SHUTDOWN=999999999999
IF %TIME_TO_VALIDATE% GEQ 000000 IF %TIME_TO_VALIDATE% LEQ 020000 SET SECONDS_TO_SHUTDOWN=7200
IF %TIME_TO_VALIDATE% GTR 020000 SET SECONDS_TO_SHUTDOWN=3600
ECHO La hora actual es: %TIME_TO_SHOW%, el computador se apagara en -T %SECONDS_TO_SHUTDOWN%
SHUTDOWN -s -t %SECONDS_TO_SHUTDOWN%
PAUSE > NUL
It is a simple flat text file saved with the extension .bat
, I tried it and it worked for me correctly validating the time and "setting" correctly the "argument" -t
, in scripts
batchs
Conditional operators are the following (so you understand how the previous code works):
EQU
- equal - same as
NEQ
- not equal - not equal - different from
LSS
- less than - less than
LEQ
- less than or equal - less than or equal to
GTR
- greater than - more than
GEQ
- greater than or equal - more or equal than
We must also say that the operators AND
and OR
do not exist but you can validate these with a double if
(like the one that appears in the code)