I cannot seem to get the if %day% EQU lines correct. I am trying to get the autoShutDown variable to "T" when the script is run between Friday night 8:30 PM and Saturday at 5:15 PM. But it seems like sometimes the formatting is different and causes the variable assignment to not work correctly.
What's the best way to set the variable? In case it makes a difference, I have Windows 8.1.
@ECHO OFF SET day=%date:~0,3% SET time=%time:~0% set "time=%time: =%" set currentDate=%date:~4,10% set autoShutDown=F if %day% EQU Fri IF %time% GEQ 20:30:00.00 set autoShutDown=T if %day% EQU Sat IF %time% LEQ 17:15:00.00 set autoShutDown=T if "%autoShutDown%"=="T" ( GOTO AUTOSHUTDOWN ) GOTO WEEKDAY :AUTOSHUTDOWN %WINDIR%\SYSTEM32\SHUTDOWN.EXE /s /t 180 /c "Shutdown in 180 seconds" /d p:4:1 :WEEKDAY
[ EDIT ] So based on what @harrymc wrote below, is the following what I should be doing?
@ECHO OFF set autoShutDown=F for /f %%C in ('wmic path Win32_LocalTime Get dayofweek^,Year^,Month^,Day^,Hour^,Minute^,Second /Format:List 2^>nul ^| find "="') do @set current%%C REM - Friday 8 PM or later if %currentDayOfWeek% EQU 5 IF %currentHour% GEQ 20 set autoShutDown=T REM - ...or Saturday earlier than 6 PM if %currentDayOfWeek% EQU 6 IF %currentHour% LEQ 17 set autoShutDown=T if "%autoShutDown%"=="T" ( GOTO AUTOSHUTDOWN ) GOTO WEEKDAY :AUTOSHUTDOWN %WINDIR%\SYSTEM32\SHUTDOWN.EXE /s /t 180 /c "Shutdown in 180 seconds" /d p:4:1 :WEEKDAY