I have opened two instances of D:\akshit folder. One I opened manually using GUI. But the other one, I created with a script that calls subprocess.Popen(). Now whenever I write the following command, only the instance opened using subprocess.Popen() is being killed:

TASKKILL /F /FI "WINDOWTITLE eq akshit" /IM explorer.exe

Can anyone explain on what basis does the taskkill decide to not kill the other instances? Can I somehow change this behavior to kill all the instances with the window title "akshit"?

  • What happens if you use TASKLIST /F /FI "WINDOWTITLE eq akshit" /IM explorer.exe? this command is to list the tasks. If it also only shows one result, then you have your answer. You can use TASKLIST to figure out what to change in order to make TASKKILL behave properly. – LPChip May 22 '18 at 11:08
  • we cant use /F or /IM with tasklist. It gives invalid argument. – akshit bhatia May 22 '18 at 11:39

It is not TaskKill's fault. While you have opened two File Explorer windows, this does not necessarily mean that you have opened two separate processes for each.

One of the settings that can impact your situation can be found under:

Folder Options → View tab → Advanced settings → "Launch folder windows in a separate process"

This setting has the following effects:

  • If this checkbox is not checked, most of the times, File Explorer windows are opened in the same explorer.exe process that hosts task bar and Start menu. This process's window title is fixed. If you kill this process, you entire Windows shell disappears.
  • If this checkbox is checked, the process that hosts task bar and Start menu is always separate from the process hosting your File Explorer windows. But still, this does not mean that you get one separate explorer.exe process for each File Explorer window. I tested this in Windows Server 2008 R2 and Windows 10 1709. I always get exactly one explorer.exe process for all my File Explorer windows and one other explorer.exe for my taskbar and Start menu. The WINDOWTITLE of that process is always the title of the File Explorer window that was open last.

One reason that subprocess.Popen() opens a separate File Explorer process could be that you are running a 32-bit Python on a 64-bit computer, in which case, subprocess.Popen() just opens a 32-bit explorer.exe. (This does not happen in all versions of Windows, but again, you didn't specify any.) Another reason is out-of-process DCOM invocation that always trips me up.

But the gist of it is:

  • Window ≠ Process
  • Thanks!! It is working fine now. Is it possible to control set this option via python script? – akshit bhatia May 22 '18 at 12:13
  • It is possible, but it won't take effect until the computer is restarted. It is a setting in Windows Registry. I am not sure exactly where, but you can probably use Sysinternals Process Monitor to find it, if a Google search didn't gave you the answer. – user477799 May 22 '18 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.