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
  • 26,555
  • 15
  • 113
  • 235
  • Just out of curiosity, why does PowerShell not work for you? It functions pretty much the same as Command Prompt. – Sam Forbis Jan 23 '20 at 14:32
  • 3
    Make it work like it did in W7>>>>https://www.tenforums.com/tutorials/72024-open-command-window-here-add-windows-10-a.html – Moab Jan 23 '20 at 14:34

6 Answers6

4

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.

Andrew Morton
  • 2,957
  • 2
  • 20
  • 29
  • I don´t get into the address bar after pressing Alt + D. Instead I get into the "File" menu. Also, how does that open a specific folder in cmd.exe? – RobertS - Reinstate Monica Jan 23 '20 at 14:28
  • 1
    @RobertS-ReinstateMonica In that case, click in the address bar. When the command prompt window opens, it will be in the directory that was showing in the main pane. – Andrew Morton Jan 23 '20 at 14:48
  • @RobertS-ReinstateMonica - By default PowerShell and the command prompt directory will initialize at that directory. I can confirm that the shortcut works as expected, it should not expand the File menu, but without specific information about the system I can't investigate the possible reasons it's not working for you. – Ramhound Jan 23 '20 at 14:48
  • @Ramhound Windows 10 Home, Version 1809, x64. – RobertS - Reinstate Monica Jan 23 '20 at 14:53
  • @RobertS-ReinstateMonica If Alt-D got you to the file menu, perhaps you let go of Alt before pressing D. That's the only way I can get it behave like that. – Andrew Morton Jan 23 '20 at 20:26
  • 3
    if `Alt+D` doesn't bring you to the address bar then probably you're not using English Windows. Use `Ctrl+L` instead. Another workaround is to press `F4` although the behavior is not exactly the same – phuclv Jan 24 '20 at 03:26
  • @phuclv Yes, it has worked with `Ctrl + L`. The source because of `Alt + D` does not work at my system is exactly the same as you said, I got a PC with german Windows distribution on it. Cool trick. – RobertS - Reinstate Monica Jan 24 '20 at 18:47
  • @RobertS-ReinstateMonica The corresponding MS help in German - [Tastaturkurzbefehle in Windows](https://support.microsoft.com/de-de/help/12445/windows-keyboard-shortcuts) - says Alt+D. Perhaps you would like to add something to the "An Diskussion teilnehmen" section at the end of that page to tell them it doesn't work. My German is inadequate for that. – Andrew Morton Jan 24 '20 at 18:55
  • @AndrewMorton I like this trick because its so simple to achieve. Can I open CMD with the focused folder as administrator in this way, too? – RobertS - Reinstate Monica Jan 24 '20 at 19:00
  • @RobertS-ReinstateMonica I don't think so. I tried with ctrl+shift+enter, which would run it as Administrator from the windowskey+R box, but that didn't do anything useful. – Andrew Morton Jan 24 '20 at 19:03
  • best answer and better than messing with the registry imo – oldboy May 23 '21 at 21:51
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
  • 455,459
  • 31
  • 526
  • 924
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
  • 1,781
  • 3
  • 11
  • 22
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
  • 26,555
  • 15
  • 113
  • 235
Io-oI
  • 7,588
  • 3
  • 12
  • 41
1

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
  • 26,555
  • 15
  • 113
  • 235
0

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

%windir%\system32\cmd.exe /k " cd\ & cd "C:\ThePath\ToOpenCMDin"
Donald Duck
  • 2,473
  • 10
  • 29
  • 45
jonadv
  • 101
  • 1