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.
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"
- 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.
- You may modify the name of the command that will be displayed in the context menu. The default string is “Open Command Line Here”.
- Double click on open_cmd_here.reg.
- At the message Are you sure you want to add the information in C:\temp\open_cmd_here.reg to the registry ?, click Yes
- A second message will display Information in C:\temp\open_cmd_here.reg has been successfully entered into the registry, click OK
- 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.
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"
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
- Microsoft XP Powertoys
- Tim Sneath’s blog: Windows Vista Secret #1: Open Command Prompt Here
- Articles from Daniel Pietri:
- Microsoft DOS cmd command
- Microsoft Support: How to add, modify, or delete registry subkeys and values by using a registration entries (.reg) file
- Cygwin Prompt Here context menus (chere) is a Cygwin package that inserts entries in the folder context menu.
- Microsoft TechNet: Script Elevation PowerToys for Windows Vista
- Scott Hanselman’s blog: Introducing PowerShell Prompt Here.
- Windows Vista Open Command Prompt Here With Elevated Privilege from Walker News.
- Windows Services for UNIX is available from the TechNet web site.
- Windows PowerShell is the new command line shell and scripting for Windows.
- Cygwin will give you a full Linux-like environment on Windows.
Legal
Microsoft, Windows and Windows Vista are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.






Pingback: links for 2009-08-20 « earth is my favourite planet
Pingback: Open bash here (Windows Explorer) : expatiari expatria
Pingback: Windows Command Prompt « programmingtipoftheday
Pingback: land