I'm trying to get a .bat file to run a reminder popup do to restrictions on my work PC (Windows 7 OS). I am unable to use windows task scheduler due to these restrictions so I need the time check to run inside the batch file itself.
Currently, I have the following:
@echo off
:check
if "%time%"=="09:51:00.00"
msg user42 Test Reminder
Timeout /t 20 /nobreak
GOTO :Check
The issue seems to be with the "if" in the third line. as the rest of the code works with this line removed.
Any advice would be much appreciated.
We would need to manipulate your time variable to make this work as expected, but we don't really want to modify system or user environment variables. So we create our own.
First we make sure the time hour value always has 2 digits by replacing whitespace with 0
as only single digit time (1,2,3..9) will have a leading space. then we remove the :
to make it a single matchable numeric value, then we simply do a match to see if the time is greater than or equal to 0951 (09:51 am) and if it is, we check if it is less than 0952 (09:52 am) meaning time has to be 09:51 any second and not 09:52 or larger.
Now we run the script every 50 seconds which will fall inside of each minute regardless, if we left it at 20 seconds, it would alert 2 or 3 times.
@echo off
:check
set mytime=%time: =0%
set mytime=%mytime::=%
if "%mytime:~0,4%" GEQ "0951" if "%mytime:~0,4%" LSS "0952" msg user42 Test Reminder
Timeout /t 50 /nobreak>nul
GOTO :Check