How to Open Command Prompt In Any Folder From Context Menu in Explorer

If you are in IT chances are you have run commands from Windows command prompt. When you open a command prompt window, the initial folder defaults to your user directory and it can be a pretty tedious task to navigate all the way to the folder you want to be in:

Default Command Prompt Window

Default Command Prompt Window

Navigating to a folder with a long name

Navigating to a folder with a long name

Wouldn’t it be cool if you could open a Command Prompt window right in the folder you have open in Windows Explorer? – You can, and it only takes a minute. In order to do it, you will need to modify a registry key that controls the context menu in Explorer. Here is a step by step example of what you need to do:

Run the Registry Editor Utility, regedit.exe:

Run the Registry Editor Utility

Run the Registry Editor Utility

Navigate to HKEY_CLASSES_ROOT\Directory\Background\shell key, right-click on it and select New > Key to create a new key:

Create a new registry key

Create a new registry key

Name the key “Open Command Prompt Here” (or anything else you would like to show on the right-click menu). Then right-click on it and select New > Key to create a key underneath it. Name the key “command”:

Create a command key

Create a command key

Select the “command” key, and you will see that a default string (REG_SZ) value has been created in the right pane, with no value set. Double-click on (Default) (or right-click and select Modify) and enter cmd.exe in the Edit String dialog:

Update the value

Update the registry value

You are done! Right-click on any folder in the left pane of Windows Explorer or white space in the right pane and select “Open Command Prompt Here” (or however you named it) to open a Command Prompt window with the working directory being the folder you are in:

You are done!

You are done!

One thing to note here is that, as you can see, there is no icon next to the “Open Command Prompt Here” in the menu. In order to add the standard command prompt icon, select Open Command Prompt Here" in the left pane and then right-click anywhere on the white space in the right pane to add a value. Select New > Expandable String Value from the context menu, name it Icon and give it a value of cmd.exe,0. In case you are wondering, this means use icon with index 0 (the first one) that is stored within cmd.exe file.

Add an icon to the context menu

Add an icon to the context menu

Now, here’s the fun part: you can achieve the same result by simply creating a .reg file, double-clicking on it and confirming you want to import the registry settings:

Open-Command-Prompt-Here-Context-Menu.reg

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\Open Command Prompt Here]
"Icon"=hex(2):63,00,6d,00,64,00,2e,00,65,00,78,00,65,00,2c,00,30,00,00,00

[HKEY_CLASSES_ROOT\Directory\Background\shell\Open Command Prompt Here\command]
@="cmd.exe"

This entry was posted in Windows and tagged , , , , , , . Bookmark the permalink.

2 Responses to How to Open Command Prompt In Any Folder From Context Menu in Explorer

  1. Joe Payne says:

    Can this same registry hack be used to open the command prompt here and then run a command from the command prompt without having to type the command into the cmd window. Could this be modified to open the command prompt then create a subdirectory (to be named in the code) in the current directory and then close the cmd window. I work with a lot of pictures that have to be resized before I can use them so I create a sub folder in the working directory called “resized”. If this could be done with just 2 clicks instead of having to go through the directory creation process in windows 7 it would save me a lot of time. Thanks. Joe

  2. ℓūfħer says:

    Yes, you can certainly do so! Following the same guide, add another key under shell (e.g. naming it “Create resize Folder”) and instead of cmd.exe use cmd.exe /C “mkdir resize”. The /C key in this case indicates to the command prompt to execute a command that is specified, in this case – a command that creates a directory called “resized”.

Leave a Reply

Your email address will not be published. Required fields are marked *