Reputation: 33
I'm trying to close an open window by its title using batch.
I got this from another question:
TASKKILL /F /FI "WINDOWTITLE eq titleofwindow"
It's called when I first open the batch file (at which point the window it's trying to close isn't open) and gives the normal "INFO: No tasks running with the specified criteria." error.
The script then runs through it's normal processes, which opens the window I'm trying to close, and then begins the script from the beginning again, calling the same taskkill command again, as it did on first opening the batch file.
However on calling it while the titled window is actually open, it kills explorer.exe, instead of just the specific window.
/EDIT Example:
@ECHO OFF
:START
SET /P TEMP=Intentionally pausing here
TASKKILL /F /FI "WINDOWTITLE eq ExampleDirectory"
COPY C:\SomeFiles\*.txt C:\ExampleDirectory\
EXPLORER /SELECT,C:\ExampleDirectory\AFile.txt
GOTO START
So it's opening the directory, and highlighting one of the files in there. When the script restarts, I want it to close that window. The visual title of the window appears as "ExampleDirectory".
Upvotes: 1
Views: 1538