Open Command Prompt in Current Folder Using Keyboard Shortcut

There are at least a couple of ways to open Command Prompt in the current folder path from a folder window. The two widely used options include running cmd.exe from the File Explorer address bar and using the Open Command window here option from the folder background context menu.

But, no built-in option exists to accomplish this using a keyboard shortcut or hotkey. This post tells you how to open Command Prompt (or admin Command Prompt) in the current directory path using the AutoHotkey automation tool.

Open Command Prompt in Current Folder Using Keyboard Shortcut

Here is to open Command Prompt in the current folder by assigning a hotkey (Winkey + C) using AutoHotkey.

  1. Download AutoHotkey and install it.
  2. Open Notepad and copy the lines of code given below
  3. Save the file with .ahk extension — e.g., open_cmd_here.ahk
    #c::opencmdhere()
    ; Press Win + C to open Command Prompt in the current directory.
    
    opencmdhere() {
        If WinActive("ahk_class CabinetWClass") || WinActive("ahk_class ExploreWClass") {
            WinHWND := WinActive()
            For win in ComObjCreate("Shell.Application").Windows
                If (win.HWND = WinHWND) {
    		currdir := SubStr(win.LocationURL, 9)
    		currdir := RegExReplace(currdir, "%20", " ")
                    Break
                }
        }
        Run, cmd, % currdir ? currdir : "C:\"
    }
    
    #+c::opencmdhereadmin()
    ; Press Win + Shift + C to open admin Command Prompt in the current directory.
    
    opencmdhereadmin() {
        If WinActive("ahk_class CabinetWClass") || WinActive("ahk_class ExploreWClass") {
            WinHWND := WinActive()
            For win in ComObjCreate("Shell.Application").Windows
                If (win.HWND = WinHWND) {
    		currdir := SubStr(win.LocationURL, 9)
    		currdir := RegExReplace(currdir, "%20", " ")
    		currdir := RegExReplace(currdir, "/", "\")
                    Break
                }
        }
    
        Run *RunAs cmd.exe /k pushd %currdir%
    }
    

    Credits: tmplinshi

  4. Double-click the .ahk file to run it.

The script runs in the background and shows up in the notification area.

open command prompt in current folder - autohotkey

  • To open a Command Prompt window from the current folder, press Win + C
  • To open admin Command Prompt from the current folder, press Win + Shift + C

It intercepts the Winkey + C as well as Win + Shift + hotkeys, gets the current File Explorer folder path and opens a Command Prompt window in the current folder location.

open command prompt in current folder - autohotkey

Note: If no folder windows are currently open, or if a non-file system folder such as This PC, Libraries or Quick access is the current folder, then pressing Winkey + C will launch Command Prompt to C:\

If the script is always running in the background, does it occupy more memory?

No! The script is extremely light-weight, and it uses only 400 Kilobytes to 2.5 MB of system memory approximately.

open command prompt in current folder - autohotkey



Other ways to open Command Prompt in the current directory

In the address bar of File Explorer, type cmd.exe and press ENTER

open command prompt in current folder - address bar cmd.exe

It launches Command Prompt in the current folder location. If a non-file system folder such as This PC or Quick access is the current folder, then running cmd.exe opens to C:\Windows\System32 by default.

Another option is to right-click an empty area in that folder and click Open command window here. If the option doesn’t appear, press the Shift key when right-clicking.

open command prompt in current folder - context menu cmdhere

If Open command window here is still missing from the right-click menu, then apply the registry edit described in the article Get back “Open command window here” context menu option in Windows 10


One small request: If you liked this post, please share this?

One "tiny" share from you would seriously help a lot with the growth of this blog. Some great suggestions:
  • Pin it!
  • Share it to your favorite blog + Facebook, Reddit
  • Tweet it!
So thank you so much for your support. It won't take more than 10 seconds of your time. The share buttons are right below. :)

Ramesh Srinivasan is passionate about Microsoft technologies and he has been a consecutive ten-time recipient of the Microsoft Most Valuable Professional award in the Windows Shell/Desktop Experience category, from 2003 to 2012. He loves to troubleshoot and write about Windows. Ramesh founded Winhelponline.com in 2005.

Leave a Comment