Open Command Window Here


On Microsoft Windows one uses intensively Windows Explorer to access files on the system. Sometimes it is also necessary to open a command line in order to run commands that are not available via Windows Explorer. Wouldn’t it be nice to open a command line in a folder from Windows Explorer? This article describes some of the options and provides complementary resources.

Open Command Window Here (XP)

Open Command Window Here (XP)

Open Command Windows Here (XP)

Open Command Windows Here (XP)

Windows 2000, XP and Vista

My favorite option is a modification in the registry. This modification can be applied using the following registry file:

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\CommandPrompt]
@="Open Command Window Here"
[HKEY_CLASSES_ROOT\Directory\shell\CommandPrompt\command]
@="cmd.exe /k pushd %L"
  1. Create a file open_cmd_here.reg in a temporary directory (Ex.: C:\temp), and paste the content of the listing above into this file.
  2. You may modify the name of the command that will be displayed in the context menu. The default string is “Open Command Line Here”.
  3. Double click on open_cmd_here.reg.
  4. At the message Are you sure you want to add the information in C:\temp\open_cmd_here.reg to the registry ?, click Yes
  5. A second message will display Information in C:\temp\open_cmd_here.reg has been successfully entered into the registry, click OK
  6. Verify that you have a new entry “Open Command Line Here” in the context menu when you right click on a folder in Windows Explorer.

Note: Modification in the registry may not be enabled if your user account does not have the proper privilege.

To uninstall, you can manually remove the key created in the registry or run the following registry script:

Windows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT\Directory\shell\CommandPrompt]

The modification in the registry works for Windows 2000, XP and Vista. But for XP and Vista there are some alternate solutions (see next sections).

Windows XP PowerToy

On Windows XP, you may download the Open Command Window Here XP PowerToy available from the Microsoft web site.

Windows Vista (shift + right-click)

Windows Vista ships with the Open Command Window Here feature included. There is a small caveat, as it is only available for the folders listed in the right pane of Windows Explorer.

In order to display the Open Command Window Here entry in the context menu, simply press Shift while making a right-click on a selected folder.

Open Command Window Here (Vista)

Open Command Window Here (Vista)

open_cmd_vista2

Open Command Window Here (Vista)

Windows Vista Elevated Mode

Windows Vista introduced higher a level of security via User Account Control (UAC). This impacts the feature “Open Command Window Here” by protecting you to execute certain commands potentially insecure. To promote “Open Command Window Here” to elevated mode to, use the following registry script:

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\runas]
@="Open Command Window Here"
[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@="cmd.exe /k pushd %L"
Open Command Windows Here As Administrator (Vista)

Open Command Windows Here As Administrator (Vista)

Open Command Windows Here As Administrator (Vista)

Open Command Windows Here As Administrator (Vista)

Other “Open Command Window Here”

It is possible to modify the registry or more simply to execute registry scripts to open other shells than the default Command Prompt. Here are a couple of examples:

Services For Unix Korn Shell

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\sfuksh]
@="Open SFU Ksh Here"
[HKEY_CLASSES_ROOT\Directory\shell\sfuksh\command]
@="C:\\WINDOWS\\system32\\POSIX.EXE /u /c /bin/ksh -l -c \"cd \\\"`chgpath -p '%L'`\\\";ksh\""

Note: Assuming Windows installed in C:\windows.

Services For Unix Bash

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\sfubash]
@="Open SFU Bash Here"
[HKEY_CLASSES_ROOT\Directory\shell\sfubash\command]
@="C:\\WINDOWS\\system32\\POSIX.EXE /u /c /bin/ksh -l -c \"cd \\\"`chgpath -p '%L'`\\\";bash\""

Note: Assuming Windows installed in C:\windows.

Cygwin Bash

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\cygwinbash]
@="Open Cygwin Bash Here"
[HKEY_CLASSES_ROOT\Directory\shell\cygwinbash\command]
@="c:\\cygwin\\bin\\bash.exe --login -i -c \"cd \\\"`cygpath -u '%L'`\\\";bash\""

Note: Assuming Windows installed in C:\windows.

PowerShell

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\powershell]
@="PowerShell Here"
[HKEY_CLASSES_ROOT\Directory\shell\powershell\command]
@="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%L'"
  • Assuming Windows installed in C:\windows.
  • To add a different title to your window, append the following to the existing powershell command: ;$host.ui.rawui.WindowTitle='Windows PowerShell'.

Directory vs. Drive

The registry scripts exposed above only apply to directories. In order to also add the same features to drives, you need to create similar entries to HKEY_CLASSES_ROOT\Drive in addition to HKEY_CLASSES_ROOT\Directory. For example:

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\CommandPrompt]
@="Open Command Window Here"
[HKEY_CLASSES_ROOT\Directory\shell\CommandPrompt\command]
@="cmd.exe /k pushd %L"
[HKEY_CLASSES_ROOT\Drive\shell\CommandPrompt]
@="Open Command Window Here"
[HKEY_CLASSES_ROOT\Drive\shell\CommandPrompt\command]
@="cmd.exe /k pushd %L"

Resources

Legal

Microsoft, Windows and Windows Vista are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.

, ,

  • http://notvalid.com Brad

    The directions for “Open Command Here” do not work properly. [HKEY_CLASSES_ROOT\Directory\shell\CommandPrompt\command] needs to be set to:

    cmd.exe /k pushd “%L”

    instead of: cmd.exe /k pushd ‘%L’

  • http://notvalid.com Brad

    Oh–and thanks; I couldn’t remember how to modify the context menu. Also that was for Windows XP and I understand that nested quotation marks might not work for an imported registry file.

  • http://www.burgaud.com/ André Burgaud

    Brad,
    You are correct. On my XP system, though it opened a command line in the correct directory, I got the following error:
    The filename, directory name, or volume label syntax is incorrect.

    I simply removed the single quotes surrounding %L and replaced “cmd.exe /k pushd ‘%L’” with “cmd.exe /k pushd %L”. I also tested successfully your suggestion by including “cmd.exe /k pushd \”%L\”" in the registry script. Both solutions are working fine with a directory name including whitespaces.

    Thanks for your feedback! – Andre -

  • http://www.moonbade.com/stuff boardtc

    Thanks a lot, exactly what I wanted for PowerShell!

  • http://tartley.com Jonathan Hartley

    This is brilliant, thanks.
    Does anyone know how to modify it so that it also works when I right click on white space inside a windows explorer window? (ie not on any of the listed files).
    Thanks for any info!

  • http://www.vailu.com vailu

    wow profesional share…. :D

  • http://www.rapid-servers.com Josh

    Nice Article, But someone know how to disable User Account Control (UAC), i dont like it :)

  • Pingback: links for 2009-08-20 « earth is my favourite planet

  • http://www.webfactorybelgium.com/ WEB FACTORY BELGIUM

    nice posting, keep writing thanks for sharing… thank you

  • http://www.burgaud.com André Burgaud

    Josh :

    Nice Article, But someone know how to disable User Account Control (UAC), i dont like it :)

    Thanks. There are a couple of ways to disable UAC:

    In the Windows Registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System set the DWORD value EnableLUA to 0.

    Or, in the Control Panel, go to User Accounts, then select Turn User Account Control on or off and unselect the check box.

  • http://livingroomdecoration.co.cc living room decoration

    Very good article, it is very useful for me and i am learn about this for few weeks…

  • Pingback: Open bash here (Windows Explorer) : expatiari expatria

  • Thomas

    Might be worth mentioning that if you want to create the entries in regedit directly, you need to remove a whole level of quoting – both outer quotes, and backslash-quoting. For example the cygwin string above becomes:

    c:\cygwin\bin\bash.exe –login -i -c “cd \”`cygpath -u ‘%L’`\”;bash”

    This works fine on Windows 7, using regedit 6.0

  • Robert Miras

    I opt to admire this post, its very informative and I have learn much. Thank you, your highly appreciated.

  • jason404

    Thanks for the information.

    Adding “NoWorkingDirectory”=”" makes the context menu entry only appear with SHIFT clicking, like the standard CMD one. This is useful if you want to keep your menus clean.

  • jason404

    Oops. I meant “Extended”=”"

    I don’t actually know what “NoWorkingDirectory”=”" does. Does anybody know?

  • Christine Bunny Hajek

    Subject: CMD @ BG-sR-Click?
    Body:
    Hello, i can see you have an extensive page on running command prompts at selected folders.
    However i (a windows XP user), wish to add to my explorer, the function of shift-right-clicking the white background space (no files or folders selected). to receive a “Start Command Prompt Here” (or in my case, “CMD Prompt here” option.

    I want to stress that this is requested feature is desired neither inside the “Folder View Frame” nor is it wanted when a file or folder is shift-Right-clicked in the “Files frame”. It is to appear Only, when the background of the current “Files frame” background is shift-Right-clicked.

    Could you please instruct me as to how this can be done or point me in a direction so i can find out? thank you.

    ~Christine

  • Pingback: Windows Command Prompt « programmingtipoftheday

  • http://iliocentrism.blogspot.com/ Ilíon

    Christine,
    I *think* you can accomplish that by making the appropriate Registry changes under the keys [HKEY_CLASSES_ROOT\Directory\Background\shell\runas] and [HKEY_CLASSES_ROOT\Directory\Background\shell\runas\command]

  • vannie

    Great post!.. Thanks for this sharing this tutorial. It’s really useful for me. Keep coming and more powers!

  • ThumpieBunnyEve

    @ Ilíon:
    I tried adding them to [HKEY_CLASSES_ROOT\Directory\Background\shell\runas] and [HKEY_CLASSES_ROOT\Directory\Background\shell\runas\command], but i see no effect. Right-clicking the blank background area of a explorer files window still does not provide a dialog entry to start a command prompt in the -current- explorer path. Does anyone know the correct registry entries to do so in winXP? Please and thank you.

  • ppamidipalli

    Thanks for the info. It worked for me on WinXP

    ~Pradeep

  • hosein

    tanks

  • JB

    When I right click and open elevated prompt, it just blinks and then goes away. Anyone know why this would happen?

  • Pingback: land