JW.
JW.

Reputation: 4951

Batch script to Launch Multiple Instances of Windows Explorer at Same Location

I have a batch script on my Windows XP desktop (LaunchWindowsExplorers.bat) which should launch a couple of instances of Windows Explorer.

It looks like this:

LaunchWindowsExplorers.bat :

start explorer "C:\SomeDirectory" 
start explorer "C:\SomeDirectory" 

When I double click the file LaunchWindowsExplorers.bat

I would expect to see

Instead, I see


What would I need to do to make this script open two instances of Windows Explorer, each of which opened at "C:\SomeDirectory"?

Thanks.

Upvotes: 5

Views: 6391

Answers (3)

wmz
wmz

Reputation: 3685

You may use explorer /n,"C:\SomeDirectory", explorer /e,"C:\SomeDirectory" or explorer /root,"C:\SomeDirectory" (depending on a view you want). Explanation of the options taken from here: http://support.microsoft.com/kb/314853:

Option Function


/n Opens a new single-pane window for the default selection. This is usually the root of the drive that Windows is installed on. If the window is already open, a duplicate opens.

/e Opens Windows Explorer in its default view.

/root,<object> Opens a window view of the specified object.

/select,<object> Opens a window view with the specified folder, file, or program selected.


What's interesting, this behavior (not showing second window for the same directory) seems specific to XP. Win7 simply starts second copy of explorer. I have not checked Vista.

Upvotes: 5

Mattias Andersson
Mattias Andersson

Reputation: 2341

I recommend you try wmz's answer before mine. My answer is a terrible, dirty hack and should only be considered as a last resort.

What my sample script does is creates a random subfolder of the folder you want to open, opens that, then removes the random subfolder and expects Explorer to gracefully move to the parent folder, which is the one you actually wanted to open.

This is terrible, terrible, terrible, but it works on my Win7 machine. :) Unfortunately, I don't have a WinXP machine/VM around, to test this properly, and it might fail completely if explorer locks the folder as in-use because it's being displayed; I can't remember when that was changed. Also, this approach requires write access to the folder and could easily be broken by unfortunate timing, or aggressive anti-virus, or any other randomness. Have I said enough, yet, about how terrible this is? :)

call :ForceStartExplorerWindow .
call :ForceStartExplorerWindow .
call :ForceStartExplorerWindow .

GOTO :EOF


:: Pass The location to open as %1
:ForceStartExplorerWindow

SETLOCAL

set __ForceStartTempDir=%1\ThisShouldNeverExist-%RANDOM%
md %__ForceStartTempDir%
start explorer %__ForceStartTempDir%

:: Hope this wait is long enough for Explorer to finish loading it...
ping -n 2 localhost >NUL

:: Hope this rd works...
rd %__ForceStartTempDir%
:: FUTURE: Consider retrying upon failure.

:: End of ForceStartExplorerWindow
GOTO :EOF

Upvotes: 1

Bertie Wheen
Bertie Wheen

Reputation: 1243

Though I'm not sure of the solution, have you tried changing it to something like:
start explorer "C:\SomeDirectory"
start explorer "C:\AnotherDirectory"
and checked what happens?
I would assume what's happening is that start explorer has a check to see if there is already an explorer open, and it only opens a new one if that's false (otherwise it just redirects the currently open one).
Sorry I couldn't be of more help.

Upvotes: 1

Related Questions