wesmantooth
wesmantooth

Reputation: 625

CMD/Batch Get Handle to Open App?

I've just made a batch file that launches a new instance of an application (Excel) and then opens a file with this instance.

However, I would like to be able to store a config file on each users computer that holds a preference setting.

The setting would tell the batch file to either open a new instance, or launch the file with an existing instance of Excel (if available). I'm good on the program flow, just want to know the commands for getting a handle to an open instance of the app. Is this possible using DOS commands, or do I need to look at designing a front loader with Excel or some other program?

Upvotes: 2

Views: 1389

Answers (1)

BaBa
BaBa

Reputation: 337

What if you just execute the Excel-File? If no excel is running, one instance will start, if an excel is running, this Excel is used to view the file. :)

Or maybe a check via TASKLIST /FI "IMAGENAME EQ EXCEL.EXE" could help to check whenever an instance is running or not:

TASKLIST /FI "IMAGENAME EQ EXCEL.EXE" | FINDSTR /I "EXCEL.EXE" >NUL 2>&1
IF ERRORLEVEL 1 GOTO :NotFound
IF ERRORLEVEL 0 GOTO :Found

Kind regards

Edited w/ Findstr & errorhandling.

Upvotes: 2

Related Questions