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)

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)

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 Window Here as Administrator (Vista)

Open Command Window 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 that Windows is installed in C:\windows

Windows Services for UNIX was discontinued and this section would apply only to non maintained Windows versions.

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\""

Windows Services for UNIX was discontinued and this section would apply only to non maintained Windows versions.

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\""

Cygwin is a collection of GNU tools that provide functionality similar to Linux on Windows. An alternative to the registry script above is to install the Cygwin package here.

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'"

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"

Conclusion

Some of the tips provided in this article may not work on later versions of windows. In addition, as Windows evolves, some of these features may be built-in the operating system. Lastly, modifying the registry manually or using registry script needs to be handled with caution. For more information about modifying the Windows registry, you may checkout How to add, modify, or delete registry subkeys and values by using a .reg file.

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