I have a folder on my Desktop named test
. I want to create a batch file in order to close the window automatically when this folder is opened with Windows Explo
The error results when you've enabled display full path in title, under Folder View options.
You may replace 'test' with full path, or disable full path display.
By default, explorer runs as single process, and any windows that open are just a thread of the process.
Normally, to close a program, you'd send a close message to the process. In this case, closing explorer.exe will close all explorer windows.
To close individual windows, you'd open each window via it's own process. This can be done via registry setting or enabling under View->Options->View->Advanced Settings: "Launch ... separate process"
a) Find PID (process ID) of window you wanna close.
via taskmanager:
1. In list of processes, click the arrow to the left of "Windows Explorer"
2. Check the window name matches the window you wanna close
3. Right click on "Windows Explorer", click "Go to Details"
4. Record the pid
via CMD:
tasklist /V /FI "IMAGENAME eq explorer.exe"
If each explorer window is open in it's own process, the above command would display the window title in the last column.
Otherwise "N/A" would be displayed.
The pid of all explorer windows would be the same. Explorer.exe processes have their own pid, and title "N/A"
If 'separate process' has been enabled eg. via Folder View option, then each window can be closed via the process id & filter option of taskkill.
To close, the desired window has to be activated first, otherwise closing with pid will close the last active window, or closing with window title filter will give error:
INFO: No tasks running with the specified criteria.
b) taskkill /pid <pid>
will close the last active window.
Repeating this command will the next window.
or taskkill /im explorer.exe /fi "windowtitle eq <window name>"
or taskkill /fi "IMAGENAME eq explorer.exe" /fi "windowtitle eq <window name>"
< window name > is not case sensitive
If full path in title bar has been enabled in Folder view, then include full path or wildcards.
To close all explorer windows:
taskkill /im explorer.exe
Tested on Win 10
This works in Windows 8.1
with explorer folder options
set to single window
but from the answer by Mofi and comments in Mofi's answer, then the solution depends on the Windows version.
What works in Windows 8.1 doesn't work in Windows XP.
TASKKILL /F /FI "WINDOWTITLE eq %userprofile%\desktop\test" /IM explorer.exe
The solution I found here worked well on XP SP 3. All you need is the small tool NirCmd:
nircmd.exe win close title "some window title"
It is not possible to close the Windows Explorer window of a folder using command taskkill
if in Windows registry under
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced
the double word SeparateProcess has the value 0 respectively option Launch folder windows in a separate process on View tab of the Folder Options is not checked.
And as foxidrive found out (read comments below) and I can also confirm, enabling this setting has on Windows XP SP3 no effect on number of explorer.exe
running on opening folders even after a restart of Windows.
Therefore it depends on version of Windows (2000, XP, Vista, 7, 8, 8.1) and the Folder Options
if it is possible at all to use the command taskkill
to close an Explorer folder window and which string to find in title bar, just the name of the folder or the full path of the folder.
On Windows XP or with Launch folder windows in a separate process not being enabled the folder window is not opened as separate task respectively as separate process.
Independent on how many folder windows are opened, the number of explorer.exe
processes for each user is always just 1. Every folder window is in real just a window of always running Windows Explorer (desktop) opened in a separate thread. Windows Explorer just pretends that the folder window is a separate task on Windows task bar and on Applications tab of the Windows task manager. But only one explorer.exe
is listed on Processes tab of Windows task manager even with multiple folder windows opened.
This behavior of Windows Explorer can be better watched with free tool Process Explorer of Sysinternals by selecting explorer.exe and viewing in lower pane on the handles of this process containing among lots of other handles also the handles of the opened folder windows.
A console application is required which finds a window by title, get the handle of this window and sends the WM_CLOSE
event message to this folder window. See for example