Rob van der Woude's Scripting Pages

Open folders in Explorer

Open the current folder in Explorer without the left side explorer bar:

START .

Open any folder in Explorer without the left side explorer bar:

START %windir%\System32\Drivers\etc

Open the current folder in Explorer with the left side explorer bar:

EXPLORER /E,.

(Tip: Padmanabha Holla)

This trick with the comma also works for other folders:

EXPLORER /E,%1

or:

EXPLORER /E,%windir%\System32\Drivers\etc

The following tip by Peter Lancashire adds some interesting possibilities:

Windows XP adds even more switches for EXPLORER.EXE, as explained in Microsoft KnowledgeBase article 314853:

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

As Peter said, the /ROOT switch can be useful in shortcuts, to prevent Explorer from scanning the entire (slow) network.

Compare the result of the following command with the previous one:

EXPLORER /E,/ROOT,%windir%\System32\Drivers\etc

And how about selecting a file or folder in the Explorer window:

EXPLORER /E,%windir%\System32\Drivers\etc,/SELECT,%windir%\System32\Drivers\etc\hosts

Unfortunately, the /ROOT switch is ignored if the /SELECT switch is used.

Credentials

Using the explorer command will always open a new instance of the running Explorer (which is Windows' so called "primary shell").
This new instance will always use the primary shell's credentials, i.e. the logged on user's credentials.

To open an Explorer look-alike with other credentials, we can use Internet Explorer.

Open the current folder in an Explorer look-alike with the credentials of the session that runs this command:

IEXPLORE -E "%CD%"

Open the current folder with Administrator credentials:

RUNAS /User:%ComputerName%\Administrator "IEXPLORE -E \"%CD%\""
Note: Depending on the Internet Explorer version, the left side explorer bar may (IE6) or may not (IE7) be visible.

This command won't work unless you add Internet Explorer's location to the PATH, or you use the fully qualified path to IEXPLORE.EXE in the command.
With a little help from REG.EXE (code shown is for version 3.0) we can look up Internet Explorer's location on-the-fly:

@ECHO OFF
SETLOCAL
SET IEReg=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE
FOR /F "tokens=3*" %%A IN ('REG Query "%IEReg%" /V ""') DO SET IExplore="%%~B"
%IExplore% -E %1
ENDLOCAL

Or, if you insist on one-liners:

FOR /F "skip=1 tokens=3*" %%A IN ('REG Query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE" /V ""') DO "%%~B" -E %*

(note the addition of skip=1)

Run Explorer in a separate process

Contrary to what I just wrote about a single Explorer process, it is possible to run Explorer as a separate process.

If you want to run each Explorer window in its own separate process, you need to tweak the registry:

REGEDIT4

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced]
"SeparateProcess"=dword:00000001

By setting the value to 1, each Explorer window will run in a separate process.
This allows you to start an Explorer process with different credentials using the basic RUNAS command.

RUNAS /User:%ComputerName%\Administrator "EXPLORER /E,\"Folder\""

It works, but I think there is a better solution.

Lately (I cannot find when this feature was introduced, it is available in Windows 7 64-bits), Explorer has a /SEPARATE switch to specify which Explorer window we want to run in a separate process.

Start an Explorer window with Administrator's credentials:

RUNAS /User:%ComputerName%\Administrator "EXPLORER /SEPARATE"

Open Folder in an Explorer window with Administrator's credentials:

RUNAS /User:%ComputerName%\Administrator "EXPLORER /SEPARATE/E,\"Folder\""

Folder may be in drive:\folder\subfolder or UNC format.
Mapped network drives, however, usually won't work because mappings are stored in the user profile.

More information can be found in Aaron Margosis' "Non-Admin" and App-Compat WebLog.

(Tip: Xavier del Peso Ribera)


page last modified: 2016-09-19; loaded in 0.0077 seconds