Perhaps you can tell Explorer to show the path in the title bar, and then use the WINDOWTITLE
filter to kill it based on that?
- Open Explorer
- Press Alt
- Click on "Tools (menu item)"
- Click on "Folder options... (menu item)"
- Click on "View (page tab)" in "Folder Options"
- Click to select "Display the full path in the title bar (Classic theme only)" in "Folder Options"
- Click on "Apply" -> "OK"
The path won't show in Explorer's title bar with the 'non-classic' themes, but it is (now) there; it's just not visible.
taskkill /F /FI "WINDOWTITLE eq C:\PathToThing\RunningInExplorer\ToRestart*"
You may need to switch to a classic theme temporarily to determine what the path/title is for the Explorer instance you want to restart.
Not 100% fool-proof, but any Explorer windows that don't have that (partial) path in the title would be safe at least. :)
edit:
Since you want to grab the one with title "N/A", you'll probably have to use a batch file so that you can tokenize the results of a TASKLIST adn tehn use those token results to use TASKKIL to kill by PID.
I found an answer over to StackOverflow.com that addresses this:
From question Taskkill an untitled process? is this answer which includes this example batch file:
@echo off
SETLOCAL enabledelayedexpansion
for /f "tokens=*" %%a in ('TASKLIST /V') do (
set s=%%a
set p=!s:~27,5!
set t=!s:~152,3!
if '!t!'=='N/A' ECHO TASKKILL /PID !p! /T
)
You'll want to change the 'TASKLIST /V' command to be more specific to Explorer.exe and such, but it should give yo a good starting point.
Killing the main explorer.exe will probably just kill all of the others since they depend on it to run. – cutrightjm – 2012-06-08T01:21:08.730
1@ekaj It does not. I am able to do it manually. Each window is an independent process. – Hod - Monica's Army – 2012-06-08T01:21:52.730
I’m interested in finding a reliable way to determine the primary (associated with the Desktop)
explorer.exe
instance as well, but for the opposite reason. I find it annoying that spawnedexplorer.exe
processes are not always exited when all of their associated windows are closed. I use the Task Manager to kill them, and tend to rely on the fact that the spawned instances are usually set to high priority (for some reason). This works fine, but if I happen to have set it to normal (for obvious reasons), then I run the risk of accidentally kill the primary process. – Synetech – 2012-06-08T03:26:44.883@Synetech The solution to that is
taskkill /f /im explorer.exe /fi "windowtitle ne N/A"
. For some reason, copy/pasting that into the cmd prompt doesn't work; you have to type it by hand. Didn't try a batch file. – Hod - Monica's Army – 2012-06-08T04:02:06.9271You have split the problem into an easy and an impossible part, solved the easy part and are now asking for help with the impossible part. It is quite likely that the "easy" part of the solution is not correct (e.g. what you are trying to do could be achieved with a group policy), so it would be nice if your question included the original problem you are trying to solve. Killing processes that do not belong to you is seldom correct. – Simon Richter – 2012-06-08T07:22:48.180