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.






#1 by Brad - February 15th, 2008 at 07:53
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’
#2 by Brad - February 15th, 2008 at 08:06
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.
#3 by André Burgaud - February 16th, 2008 at 09:08
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 -
#4 by boardtc - April 3rd, 2008 at 09:57
Thanks a lot, exactly what I wanted for PowerShell!
#5 by Jonathan Hartley - September 11th, 2008 at 12:20
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!
#6 by vailu - August 15th, 2009 at 14:25
wow profesional share….
#7 by Josh - August 18th, 2009 at 07:46
Nice Article, But someone know how to disable User Account Control (UAC), i dont like it
#8 by WEB FACTORY BELGIUM - August 21st, 2009 at 20:08
nice posting, keep writing thanks for sharing… thank you
#9 by André Burgaud - August 28th, 2009 at 21:48
Thanks. There are a couple of ways to disable UAC:
In the Windows Registry key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Systemset 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.
#10 by living room decoration - October 18th, 2009 at 02:11
Very good article, it is very useful for me and i am learn about this for few weeks…
#11 by Thomas - March 22nd, 2010 at 04:27
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