1

I'm looking for a shortcut kind of way in Windows 10 to open cmd.exe with a directory/folder from the Windows Explorer, so that I have this specific folder as actual working directory in the command prompt.

I know the trick with holding Shift and Right-Click on the relative folder in Explorer, where you are getting an extra menu option for open it in cmd.exe, as explained here:

How to open a terminal quickly from a file explorer at a folder in Windows 7?

But unfortunately that does not work in Windows 10, it only works for Windows 7 and Windows 8. In Windows 10 you only have the option to open it in the PowerShell, but not in the command prompt / cmd.exe.

  • How do I open a folder from Windows Explorer in cmd.exe without doing too much typing?
phuclv
  • 30,396
  • 15
  • 136
  • 260

6 Answers6

5

Press Alt+D to go to the address bar*, or click in it and make sure everything is selected (it should be by default). Alternatively, user phuclv informs us that Ctrl+L also selects the address bar.

Type cmd and press Enter.


You can do the same to get a PowerShell window, just type powershell instead of cmd.


* Microsoft: Keyboard shortcuts in Windows.

2

It does work for Windows 10. There are already many duplicate questions:

Basically just take ownership of the HKEY_CLASSES_ROOT\Directory\shell\cmd key and rename the DWORD HideBasedOnVelocityId to ShowBasedOnVelocityId. For more details read

You can also get the menu item "Command Prompt Here" without shift key in Windows 10, or Add menu items to SHIFT + right click menu on Windows


Alternatively just use Andrew Richards' Enhancing the “Open Command Prompt here” Context Menu experience tweak and have the option to run cmd/powershell/bash... both as normal and elevated rights

run cmd elevated

run powershell elevated

Just import the below *.reg file (or copy from the MSDN blog above)

Windows Registry Editor Version 5.00

; Command Prompt

[HKEY_CLASSES_ROOT\Directory\shell\01MenuCmd] "MUIVerb"="Command Prompts" "Icon"="cmd.exe" "ExtendedSubCommandsKey"="Directory\ContextMenus\MenuCmd"

[HKEY_CLASSES_ROOT\Directory\background\shell\01MenuCmd] "MUIVerb"="Command Prompts" "Icon"="cmd.exe" "ExtendedSubCommandsKey"="Directory\ContextMenus\MenuCmd"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuCmd\shell\open] "MUIVerb"="Command Prompt" "Icon"="cmd.exe"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuCmd\shell\open\command] @="cmd.exe /s /k pushd "%V""

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuCmd\shell\runas] "MUIVerb"="Command Prompt Elevated" "Icon"="cmd.exe" "HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuCmd\shell\runas\command] @="cmd.exe /s /k pushd "%V""

; PowerShell

[HKEY_CLASSES_ROOT\Directory\shell\02MenuPowerShell] "MUIVerb"="PowerShell Prompts" "Icon"="powershell.exe" "ExtendedSubCommandsKey"="Directory\ContextMenus\MenuPowerShell"

[HKEY_CLASSES_ROOT\Directory\background\shell\02MenuPowerShell] "MUIVerb"="PowerShell Prompts" "Icon"="powershell.exe" "ExtendedSubCommandsKey"="Directory\ContextMenus\MenuPowerShell"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuPowerShell\shell\open] "MUIVerb"="PowerShell" "Icon"="powershell.exe"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuPowerShell\shell\open\command] @="powershell.exe -noexit -command Set-Location '%V'"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuPowerShell\shell\runas] "MUIVerb"="PowerShell Elevated" "Icon"="powershell.exe" "HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuPowerShell\shell\runas\command] @="powershell.exe -noexit -command Set-Location '%V'"

; Ensure OS Entries are on the Extended Menu (Shift-Right Click)

[HKEY_CLASSES_ROOT\Directory\shell\cmd] "Extended"=""

[HKEY_CLASSES_ROOT\Directory\background\shell\cmd] "Extended"=""

[HKEY_CLASSES_ROOT\Directory\shell\Powershell] "Extended"=""

[HKEY_CLASSES_ROOT\Directory\background\shell\Powershell] "Extended"=""

phuclv
  • 30,396
  • 15
  • 136
  • 260
1

You may use the free key-remapping product AutoHotkey.

Here is a script that will start the Command Prompt on the current folder in Explorer when F12 is clicked.

#IfWinActive ahk_class CabinetWClass
~F12::
    ControlGetText, _Path, toolbarwindow322, ahk_class CabinetWClass
    StringReplace, _Path, _Path,% "Address: ",% ""
    Run %comspec%, %_Path%

After installing AutoHotKey, put the above text in a .ahk file and double-click it to test. You may stop the script by right-click on the green H icon in the traybar and choosing Exit. To have it run on login, place it in the Startup group at
C:\Users\USER-NAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.

For choosing another hotkey than F12, see AutoHotkey List of Keys.

harrymc
  • 498,455
1

Shamelessly copied from quick reference : add-open-command-window-here-windows-10-context-menu by editing registry keys

Adding ‘Open command window here’ Option to the Windows 10 Context Menu of a Folder

Step One: Press Windows key and + R from the keyboard to open the Run command. Type regedit and then hit enter from the keyboard to open the registry.

Step Two: Go to the following path:

HKEY_CLASSES_ROOT\Directory\shell\cmd

Right-click the cmd key. Scroll to Permissions and then click it.

Step Three: Click Advanced.

Step Four: Click the Change link.

Step Five: Type your user account name and click ‘Check Names’ to verify it. Click OK when you are done.

Step Six: Check ‘Replace owner on subcontainers and objects’. Click Apply and then OK.

Step Seven: In ‘Permissions for cmd’ window, select the Administrator account. Check Allow for full control option. Click Apply and then OK.

Step Eight: Inside the cmd key (right window), right click HideBasedOnVelocityId and then click Rename.

Step Nine: Rename the DWORD from HideBasedOnVelocityId to ShowBasedOnVelocityId, then hit Enter from the keyboard.

You are done. When you press shift from the keyboard and then right-click on any folder, you will have the ‘Open command window here’ option on the Windows 10 Context Menu.

Adding ‘Open command window here’ Option to the Context Menu of Background

Here are the few steps you need to take:

Step One: Press Windows key + R simultaneously to open the Run command. Type regedit and hit enter from the keyboard to open the registry.

Step Two: Go to the following path:

HKEY_CLASSES_ROOT\Directory\Background\shell\cmd

Step Three: Right-click the cmd key and then click Permissions.

Step Four: Click Advanced.

Step Five: Click the change link on top of the window in front of owner option.

Step Six: Type your user account name and click ‘Check Names’ to verify it. Click OK when you are done.

Step Seven: Check ‘Replace owner on subcontainers and objects’ option. Click Apply and then OK.

Step Eight: In permissions window, choose the administrator user. Check Allow for Full Control option, click Apply and then OK.

Step Nine: Inside the cmd key (right window), right-click the HideBasedOnVelocityId DWORD and then click Rename.

Step Ten: Change the DWORD name from HideBasedOnVelocityId to ShowBasedOnVelocityId and press Enter from the keyboard.

That’s all. When you press shift and right-click anywhere on your windows background, you will have an option of ‘Open command window here’ as shown in the following screenshot from Windows 10.

Madhubala
  • 2,008
1
  • So, save this code as file./, and run or click (need admin rights).

    Windows Registry Editor Version 5.00;Command Prompt Here[HKEY_CLASSES_ROOT\Directory\shell\runas]@="Command Prompt Here"[HKEY_CLASSES_ROOT\Directory\shell\runas\command]@="cmd.exe /s /k pushd \"%V\""
    cls & echo/ & "%__APPDIR__%reg.exe" import "%~f0" & "%__APPDIR__%timeout" -1 
    
  • This is the reg part of hybrid with / file:

    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\Directory\shell\runas]
    @="Command Prompt Here"
    
    [HKEY_CLASSES_ROOT\Directory\shell\runas\command]
    @="cmd.exe /s /k pushd \"%V\""
    
  • You get this menu context: Command Prompt Here

  • You don't need additional startup script or holding Shift and Right-Click.

phuclv
  • 30,396
  • 15
  • 136
  • 260
Io-oI
  • 9,237
0

Right click on desktop, add shortcut and write this as target:

%windir%\system32\cmd.exe /k " cd\ & cd "C:\ThePath\ToOpenCMDin"
jonadv
  • 101