此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
: z; V& A! y2 f" X 正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
$ [3 n# S. \- w# ?" K0 U" ^ 方式一:) n/ ^& Z3 r# T; l7 u! B
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,3 _0 U* F3 W# [8 A8 o, J' C6 J
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
* V6 ~' Z" w+ ~$ U% _! l* l. O/ H HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。1 \, R W5 k! F# Z1 d
方式二:/ ~6 r) G7 u; Q" l
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
; i$ p1 @+ r9 }# g9 a8 i7 U9 ` SetTitleMatchMode RegEx
4 x- m" i V/ j$ y1 p return8 p9 R% f- C$ ~& Q5 o
; Stuff to do when Windows Explorer is open
$ L9 Q' _4 Q) a/ s4 N ;8 f4 G% f2 N' U, h
#IfWinActive ahk_class ExploreWClass|CabinetWClass
2 B4 W3 @& `; C6 ^1 c- K. Q/ G! ~ ; open ‘cmd’ in the current directory
" C9 C$ T E* [1 z7 r( }: _* P- ? ;$ X, _" ~$ b8 x/ B5 \3 Z
#c::* w9 t* |) |" Z
OpenCmdInCurrent(). R3 B: \. y ]1 `
return* J6 s3 n7 [. v, W9 ]" {
#IfWinActive
, v0 S9 y% N8 D. k- \5 B/ r+ v" b ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.$ w) P" e9 I R$ w3 x P$ R. X
; Note: expecting to be run when the active window is Explorer.
3 v) ?- a6 S1 `3 A6 t9 F ;
% G# `! w* H. l; p4 T ?" G. Z OpenCmdInCurrent()
/ t- g! m, \, `2 `' A" G8 H {
' N$ a) s* h& J" ]: Z ; This is required to get the full path of the file from the address bar8 r. ~ B- s$ `- @4 y/ J: s5 i
WinGetText, full_path, A
. l( a, W J: p$ s3 |) W$ S* V; H ; Split on newline (`n)
& Z: }/ ]9 F6 _/ { ~& C: D, F StringSplit, word_array, full_path, `n; y. G: L7 ]% {. I2 y, i
; Take the first element from the array; b' F, ]( U& \8 i% n" r
full_path = %word_array1%
: k; s4 F2 x, U* P ; strip to bare address. C* |. C- `" `4 V8 ~# g
full_path := RegExReplace(full_path, “地址: “, “”)
P4 z. g& }8 t. _% F- O5 T ; Just in case – remove all carriage returns (`r)
' `3 C* ^+ s% L1 @3 w4 n q4 ^ StringReplace, full_path, full_path, `r, , all9 j6 D4 ~9 [: `' S4 e7 j- V/ C
IfInString full_path, \1 a2 G. M$ `6 c' y1 k- v
{1 L v# s! C2 S( C0 _& V6 x" t. }! d
Run, cmd /K cd /D “%full_path%”3 J# t9 K" _0 _2 W
}
* _, k. T) G1 G1 ? else/ A6 o, x2 g7 |1 v( \, I
{/ k! k. ~0 T$ ~* P3 g% I
Run, cmd /K cd /D “C:\ ”
) f; B& `0 G2 } }
: k! v# [, B: t6 u }
% Q4 H* C4 v5 q 把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
, v% G& d% a9 c 这段小代码肯能有两个你需要修改的地方* O9 ^/ o: J+ P8 {/ Z+ `
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
7 ~6 C4 z% i9 b( \+ N 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
" a) G! Q4 U9 R$ x |