Open A New Command Prompt From Explorer With A Hotkey
Reader Kevin used his ubergeeky AutoHotkey scripting skills to create a hotkey that opens a command prompt window at the same location as the folder you are browsing in Windows Explorer.
To use the script, you simply hit the Ctrl+Alt+H shortcut key sequence while looking at a folder in Windows Explorer and a new command prompt window will open, already set to the same working directory. We’ve already covered how to open a command prompt window from the context menu, but this method is even simpler.
To create this hotkey for yourself, create a new AutoHotkey script or add the following to your existing script:
#IfWinActive ahk_class CabinetWClass ; for use in explorer.
^!h::
ClipSaved := ClipboardAll
Send !d
Sleep 10
Send ^c
Run, cmd /K “cd `”%clipboard%`”"
Clipboard := ClipSaved
ClipSaved =
return
#IfWinActive
Once you’ve added, saved, and launched the script, you should be able to start using the hotkey immediately. Thanks, Kevin!
For more Windows shortcut goodness, check out how to make Win+E open the folder of your choice, learn how to use Caps Lock for hand-friendly navigation, and see how Taskbar Overlord tweaks the Windows 7 taskbar. Brand new to AutoHotKey and its time-saving ways? Peek at our beginner’s guide to learn how to add this script, or write your own.
Comments (AU Comments | US Comments)
@Phoshi: You're right Phoshi, but I'm used to keep my left hand on the left side of the keyboard and my right hand keeps control of the mouse almost all of the time.
I've become very fast using a "clever" combination of these two.
Anyway, AutoHotkey is never a wrong thing :-)
@cookiez: Didn't know about that one. Thanks ;)
in fact it's Alt-D, "cmd",
cookiez
well, what about
Ald-D, "cmd", Enter?
cookiez
Microsoft already has a Powertoy called "Open Command Window Here" which allows you to open a command prompt by right clicking any folder, and it will appear in the contextual menu:
[www.microsoft.com]
maxshiff
@Phoshi: Love this one. Far better than CTRL+ALT+H (What the... CTRL+ALT+C for console would be more suited and less of a spread (one handed keyboard hell yeah), or T for terminal) but frankly as you said, nobody uses the right winkey.
polobunny
There is a prog called "Hoekey" that I found made this action a lot easier to set up and use. App found here:
[www.bcheck.net]
In its config file, you'll see an entry similar to this:
~C=Run|cmd.exe|||%c
~C means Winkey+C. I chose that combo just for convenience.
Also, "display the full path in the title bar needs to be given a checkmark in Folder Options (under the View tab), else this trick won't work. This applies to both AHK and Hoekey.
Anyway, AHK is a bit overkill, and this is just another example. Happy Lifehacking!
paintbox
@Phoshi: I use "@echo off" all the time for longer batch files, but for one-liners I sometimes leave it off. Definitely makes it cleaner though - good point!
Dustin L.
@joemccall86: Agreed that this is much better than the clipboard hack.
MkFly
@joemccall86: sweet, this one actually works :)
I like this much more than the clipboard acrobatics in the article. I've added it to my main ahk script.
mahumphrey
@Dustin L.: May I suggest an "@ECHO OFF" at the start of that? Cleaner output, is all. Thanks for the tip, though, this should be useful :)
@Phoshi: That there script triggers in RWin (Because seriously, who uses RWin?), opens a terminal at the focused explorer window. If no such window is focused, any highlighted path is used, and if nothing is highlighted, a user configurable default is used. :awesome:
@Phoshi: Right, seeing as the theme of the day is our own versions:
RWin::
SetTitleMatchMode, 2
IfWinExist, ahk_class ConsoleWindowClass
{
WinActivate
WinWaitActive
}
else ifwinactive ahk_class CabinetWClass
{
ClipSaved := ClipboardAll
Send !d
Sleep 10
Send ^c
Run, cmd /K "cd `"%clipboard%`""
Clipboard := ClipSaved
ClipSaved =
}
else
{
ClipSaved := ClipboardAll
Clipboard = "C:\Users\Andrew\Documents\"
Send ^c
Run, cmd /K "cd `"%clipboard%`""
Clipboard := ClipSaved
ClipSaved =
}
return
I use FastExplorer to give me this nice menu:

All of which open to the current directory from whence I clicked.
MkFly
Haha, I should really put a minimum wait time before I post revisions. Here's my final:
^!h::
ControlGetText, current_path, Edit1, A
Run, cmd, %current_path%
return
I like it a lot better than my first revision.
joemccall86
I made a batch file to do the opposite: open an explorer window from the current path on the command line. I named it xh.bat (Explorer Here) and put it in a directory in my system path. It's a simple one-liner.
explorer /e,.
Dustin L.
@CrunchFlake: Keyboard! If I have to move my hand the 3 inches to my mouse, I am slightly slower, plus I'll be typing into the terminal anyway.
oh, ok, that is nice.
I've been using the right winkey to pop one up at any highlighted path - this should be a great addition to that (because doing the highlighted path is incredibly useful, actually!)
Also, thanks to Kevin for the original. I submitted a script to LH only to find that there was an easier way to do it after the script was posted. One of the comments led me to understanding how to use the controls in AHK. Cheers!
joemccall86
@Open Command Window Here PowerToy, but I may start using this since I'm more of a keyboard guy myself.
Dustin L.
Here's a version that uses the direct API:
#h::
ControlGetText, current_path, Edit1, ahk_class ExploreWClass ; can also be ahk_class CabinetWClass
Run, cmd /K "cd `"%current_path%`""
return
joemccall86
go HTG go! keyboarders lav 'ya! :-)
@CrunchFlake: Your rain was already mentioned in the article. =)
Yes, it's true that there are loads of ways to do common tasks - we just like to give people options. I prefer using the keyboard whenever possible.
@CrunchFlake: sorry, it must be "right-clicking" of course
I don't want to rain on your parade, but in Vista, you simply have to hold down the SHIFT-Key while left-clicking.
You can then choose the open the command prompt at the same location :-)