Closing window by title kills explorer in batch

ellm62

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".

wOxxOm

The Explorer windows should be closed by sending a special WM_CLOSE message which isn't available natively in batch files.

Use an external utility, for example nircmd:

nircmd win close title "DirectoryName"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related