此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。% x/ @- H6 Q6 W3 ]! G
正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
. ~# R3 n2 ^- ]% V& ` 方式一:* ~; }, E" _4 K: L' \3 a; W& y
在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表," V; ^# }) y* w U: J/ _
去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
8 N3 a$ O4 |, v5 @ HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。: q2 ?5 \( y* F! ~
方式二:1 |' y0 T) i5 V3 t5 }) ]
用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:% v% Q; C- {; j- u9 F
SetTitleMatchMode RegEx9 u7 ]9 Y1 }: ^4 Q( f. b% D
return
" z% v' N/ X! Z1 y' K ; Stuff to do when Windows Explorer is open9 e) ]5 S9 L2 x# d: p: V
;
) A6 h* `6 V! n$ ]1 f #IfWinActive ahk_class ExploreWClass|CabinetWClass) J6 ]. ?9 {" p9 S. H) R: q
; open ‘cmd’ in the current directory
6 u, P) z+ b$ | ;
7 e& J$ V/ C# H2 g2 b3 H #c::7 n# t6 N) U5 h1 U
OpenCmdInCurrent()
& ~( w- u; }8 |/ S return2 k; R1 R) t9 q N0 Z1 q
#IfWinActive1 J% \- r2 D. k- X* }- H
; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
* |4 ^& w8 W4 J+ j% O$ ]6 E ; Note: expecting to be run when the active window is Explorer.7 x9 C, A/ T4 o$ L R
;3 M L' n; k7 c( N8 f# W
OpenCmdInCurrent()
6 t1 M; p9 }2 Q$ d) O6 X. S {
9 v3 s) K7 ]4 Z0 x, [4 P: S! t ; This is required to get the full path of the file from the address bar
- g# }1 y7 o) r* S, V WinGetText, full_path, A% D. j! c; K" s7 m& L2 W' m9 O% l
; Split on newline (`n)9 x" u0 j |1 {2 ?4 [
StringSplit, word_array, full_path, `n
. I- I# h: R! J$ O- X" h7 V, P ; Take the first element from the array' C* }$ M) o/ O2 V' P8 V! P3 C
full_path = %word_array1%
8 }( h3 o9 U$ y3 v ; strip to bare address
* X0 F+ A; N8 g, ] full_path := RegExReplace(full_path, “地址: “, “”)$ m7 ~6 ]1 ~0 ?/ h5 E& v4 d
; Just in case – remove all carriage returns (`r)! x, @" G) j* R8 |5 b
StringReplace, full_path, full_path, `r, , all2 j0 J; V, D4 z3 I: u" u6 A u
IfInString full_path, \
* ~ t) ?1 }1 F% _ {
# o7 l/ `3 ^4 `0 D7 w1 R Run, cmd /K cd /D “%full_path%”, V1 a0 a7 h2 H3 Q
}5 D) M9 @" i! i$ ^3 k
else
, L+ J1 h' t! r b {
' v3 y1 C, d) e8 [1 ]. C" { Run, cmd /K cd /D “C:\ ”
! g" u k0 c5 Y) l5 Q }' K6 s0 w2 {% ^/ q# L
}# y @7 @' u+ c
把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。3 j5 ^7 k- |' b0 `! _4 S
这段小代码肯能有两个你需要修改的地方! u7 y/ T: z0 o/ e+ l" Q% ]
1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
/ L+ T$ I4 {, T9 [ 2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
$ p: d5 A4 V: C6 w. A |