Reputation: 56
I have been trying to set something up using batch. What I have been trying to set up is something that would open an excel spreadsheet containing some of the homework I had written up that I needed to get done. Though, I had run into a small problem when I had tried to check if the spreadsheet was open. I tried looking at a few solutions to my problem but I never really understood how to use them or they weren't made for xlxs. What I currently have is this code:
@echo off
SET "stime=16:00:00.00"
SET "etime=24:00:00.00"
:start
IF %time% GEQ %stime% (
IF %time% LEQ %etime% (
START Homework.xlsx
ECHO Hey
GOTO start
)
) ELSE (
GOTO start
)
IF %time% LEQ %etime% (
IF %time% GEQ %stime% (
START Homework.xlsx
ECHO Hey
GOTO start
)
) ELSE (
GOTO start
)
Upvotes: 1
Views: 2573
Reputation: 241
The thing is your code is looping like a fork bomb, I guess you're trying to stop the loop by verifying if an instance of Excel is running.
tasklist /FI "IMAGENAME eq EXCEL.EXE" 2>NUL | find /I /N "EXCEL.EXE">NUL
if "%ERRORLEVEL%"=="0" //commands here
It will check if any excel file open, running, or even previewed in preview pane.
Upvotes: 3