How can I open a command prompt in current folder with a keyboard shortcut?

285,250

Solution 1

Use this keyboard shortcut: Shift + Menu, W, Enter

  1. Shift + Menu (alternatively, Shift + F10), (opens extended right-click menu in current folder)

  2. W (selects "Open Command Window Here"),

  3. Enter (activates selection; required since "New" is also selectable with W)

The Menu key refers to the special key introduced by Microsoft, usually to the right of the right Win key.

This shortcut is available on a default installation of Windows (7) without any 3rd party software.


The AHK way. You just need to press Win + C (or whatever you want to define it as.):

SetTitleMatchMode RegEx
return

; Stuff to do when Windows Explorer is open
;
#IfWinActive ahk_class ExploreWClass|CabinetWClass

    ; create new text file
    ;
    #t::Send !fwt

    ; open 'cmd' in the current directory
    ;
    #c::
        OpenCmdInCurrent()
    return
#IfWinActive


; Opens the command shell 'cmd' in the directory browsed in Explorer.
; Note: expecting to be run when the active window is Explorer.
;
OpenCmdInCurrent()
{
    ; This is required to get the full path of the file from the address bar
    WinGetText, full_path, A

    ; Split on newline (`n)
    StringSplit, word_array, full_path, `n

    ; Find and take the element from the array that contains address
    Loop, %word_array0%
    {
        IfInString, word_array%A_Index%, Address
        {
            full_path := word_array%A_Index%
            break
        }
    }  

    ; strip to bare address
    full_path := RegExReplace(full_path, "^Address: ", "")

    ; Just in case - remove all carriage returns (`r)
    StringReplace, full_path, full_path, `r, , all


    IfInString full_path, \
    {
        Run,  cmd /K cd /D "%full_path%"
    }
    else
    {
        Run, cmd /K cd /D "C:\ "
    }
}

As a bonus, the script above also creates a new text file with this shortcut: Win + T

Credit to: Eli Bendersky

Solution 2

Press Alt+D, type cmd and press Enter. For more details see blog post here.

Solution 3

the native way to do something similar in windows7 is to hold down shift while pressing the right mouse onto the folder you want to "command prompt" to and a new menu item will appear in your context menu offering you exactly that: "open command prompt here".

alt text

if you want pure keyboard action then you have to do this:

  • open regedit
  • go to HKEY_CLASSES_ROOT\Directory\shell\cmd and rename the Extended key to Extended_save
  • go to HKEY_CLASSES_ROOT\Drive\shell\cmd and rename the Extended key toExtended_save`

this adds the "open command window here" entry to the context menu permanently. you can trigger this entry by pressing:

  • alt
  • let go, context menu opens
  • press the "underscored" character of the "open command window here" entry or go down with your cursor keys and hit enter

the name of the menu entry is labled according to the language of your OS.

an alternative route is to do this:

  • open the folder you want in the command prompt via the explorer
  • f4
  • ctrla
  • ctrlc
  • winr
  • cmd /k cd ctrlventer

which grabs the current path from the address bar of explorer and executes cmd /k cd PATH. with autohotkeys you can do the same, but i do not know autohotkeys.

Solution 4

From how-to-open-cmd-in-current-folder-by-shortcut-windows-10

If you are using Windows 8/10, there is a faster and original way :

Alt + F, P

Just three key and type twice , without help of another program.

Solution 5

As of the latest Windows 10 update, Leftium's answer's Shift + Menu, W method no longer works. However, a small modification can present a workaround, albeit with a few more keystrokes.

The problem is that Command Prompt is no longer available in the Extended Right-Click Menu. Instead, you now have Windows Powershell.

Shift + Menu, S opens up Windows Powershell in the target folder. Once in Windows Powershell, type cmd then press Enter.

This will give you access to Command Prompt within Windows Powershell.

P.S.

Ashwin Nanjappa's method of Ctrl + L, type cmd then press Enter works. However, it is elegant only if you do not intend to return to the Windows Explorer window to continue navigating among directories. Unfortunately the method brings your cursor in Windows Explorer away from the main window and requires a number of Tab keystrokes to get it back to where you can navigate folders using the arrow keys. This can be frustrating as there is limited visual confirmation when you are pressing those Tab keystrokes.

Whereas Windows Powershell does work in most ways identically to Command Prompt, I have encountered at least one case in which Windows Powershell was erroneously misreading my @tags (when I was generating javadocs) and not producing the desired result. By typing cmd then Enter within Windows Powershell, you can use Command Prompt instead which overcomes such issues.

Share:
285,250

Related videos on Youtube

Gemili
Author by

Gemili

Updated on September 17, 2022

Comments

  • Gemili
    Gemili over 1 year

    How can I open a command prompt in current folder with a keyboard shortcut in Windows 7?
    Is there any way to implement this?
    I think Autohotkey could do this, but don't know how.

  • akira
    akira over 13 years
    ah, shift-menu is nice.
  • Jonathan
    Jonathan about 13 years
    How do you use this script exactly?
  • Leftium
    Leftium about 13 years
    @Jonathan: Install Auto-HotKey (autohotkey.com). Copy the script contents to the AutoHotkey.ahk file. (probably in %USERPROFILE%\documents\) Restart Auto-Hotkey.
  • divillysausages
    divillysausages about 11 years
    nice! the other option doesn't seem to show the "open command window here" option unless you right-click on a folder - inside the folder, it doesn't show
  • Ed Orsi
    Ed Orsi almost 10 years
    This opens a cmd window, but it does not open one at the current directory. The same thing can be accomplished with win+r, cmd
  • Lucas
    Lucas over 9 years
    This was the only working solution out of all the AutoHotkey snippets I found on the web. Thanks a lot!
  • boleslaw.smialy
    boleslaw.smialy almost 9 years
    Does not work for me.
  • Canadian Luke
    Canadian Luke almost 9 years
    Alt+D select the Address Bar, not a menu
  • foobarbaz
    foobarbaz almost 9 years
    Seems to only work on German languaged Windows versions
  • Canadian Luke
    Canadian Luke almost 9 years
    Edit your answer then I can remove the down vote
  • MiniRagnarok
    MiniRagnarok almost 9 years
    Note - You do not need to press Alt+d for this to work. All I had to do in Windows 7 was type cmd into the path of windows explorer and press enter. Alt+d just automatically selects the current path.
  • pkr
    pkr over 8 years
    Ctrl+L is an alternative.
  • jiggunjer
    jiggunjer over 8 years
    any way to get an elevated console?
  • jiggunjer
    jiggunjer over 8 years
    Also doesn't work for the desktop, if you count that as a current folder...
  • danicotra
    danicotra over 7 years
    @boleslaw.smialy : maybe it is you're not using an American/English version of Windows? (With the Italian wersion you should use 'f' instead of 'w' for instance)
  • john c. j.
    john c. j. about 7 years
    May I ask you, just of curiosity, why you changed original script in this line: Loop, %word_array0%... instead of keeping original full_path = %word_array1%?
  • Leftium
    Leftium about 7 years
    @johnc.j.: Honestly, it was so long ago I don't even recall modifying the original script. The difference my version checks all array elements for the address, instead of just assuming the address is in the first element.
  • MagTun
    MagTun almost 5 years
    I tried this but it doesn't open the cmd in the open folder but in system32
  • Annie Lagang
    Annie Lagang almost 5 years
    Thanks. Because of your tip, I was able to discover Alt + F, M A is to open command prompt in Admin mode. :)
  • phuclv
    phuclv over 4 years
    Alt+D works in English Windows. An alternative shortcut is Ctrl+L. A similar but not equivalent solution is F4
  • The_Learner
    The_Learner over 3 years
    How to open the same as administrator from current folder
  • user26742873
    user26742873 over 3 years
    There is a much neater version of AHK script down. (by using win.LocationURL, much easier to parse)
  • Georgi Peev
    Georgi Peev almost 3 years
    Additional note to that. Whatever you execute in that search bar will be treated as a normal CMD command. For example I can fast execute a g++ command.
  • pholpar
    pholpar over 2 years
    Thanks! In the German version of Windows is the hot key ALT + D, E