I have been coding a small thing that, rather stupidly, has been taking me a while. What it is meant to do is always have a certain excel spreadsheet (named Homework.xlsx) open between two certain times (4:30 and 5:30). The thing is it doesn't actually stay open to check for those times, even though I have it set to a loop that repeats every minute. Here is the code:
SET "stime=16:30:00.00"
SET "etime=17:30:00.00"
:start
TASKLIST /FI "IMAGENAME EQ EXCEL.EXE" 2>NUL | FIND /I /N "EXCEL.EXE" >NUL
IF %ERRORLEVEL% = 0 (
SET Erunning=true
) ELSE (
SET Erunning=false
)
IF EXIST C:\Users\Hunter\Documents\HOMEWORKSHEETISOPEN.txt (
IF %Erunning%=false (
DEL C:\Users\Hunter\Documents\HOMEWORKSHEETISOPEN.txt
)
)
IF EXIST C:\Users\Hunter\Documents\HOMEWORKSHEETISOPEN.txt (
SET running=true
) ELSE (
SET running=false
)
FOR /F %%F IN ('wmic path win32_localtime get dayofweek^|Findstr [0-6]') DO SET DOW=%%F
IF %time% GEQ %stime% IF %time% LEQ %etime% IF %running%==false IF %DOW% NEQ 6 IF %DOW% NEQ 0 (
START /MAX C:\Users\Hunter\OneDrive\Homework.xlsx
ECHO IMRUNNING > C:\Users\Hunter\Documents\HOMEWORKSHEETISOPEN.txt
)
TIMEOUT 60 /NOBREAK > NUL
GOTO start