Batch file IF %time% not working
I'm trying to make a batch file to shutdown PCs if they're used out of the allowed times. It'll be triggered on boot, but because you can't have 'if and' triggers in Windows Task Scheduler it was necessary to build the time check in to the script.
I've used the following method but it isn't working. Does anybody know why?
IF "%TIME:~0,5%" GEQ "19:58" IF "%TIME:~0,5%" LSS "08:58" (MSG * "Your device has not been authorised for use at this time and will now shutdown." && SHUTDOWN -s -t 120)
Try this:
SET "ADJUSTEDTIME=%TIME: =0%"
IF "%ADJUSTEDTIME:~0,5%" GEQ "19:58" GOTO :SHUTDOWN
IF "%ADJUSTEDTIME:~0,5%" LSS "08:58" GOTO :SHUTDOWN
GOTO :EOF
:SHUTDOWN
MSG * "Your device has not been authorised for use at this time and will now shutdown."
SHUTDOWN -s -t 120