电脑互动吧

 找回密码
 注册
查看: 6118|回复: 0

Windows下更高效的打开你的命令行

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
+ t* D; I( a( [/ T  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
6 S9 S- _" C! D" Y  方式一:
2 c( U; ~+ y. H  |8 j  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,' S6 m2 x2 [: `: ]
  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
) T" W5 C4 @3 i  F8 w2 q" H6 d  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
# U- U9 @6 u5 H8 {* b$ y" x4 d3 d  方式二:
* F/ I$ a; F% |& e& V8 D: T. K) K  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:% |5 ^: m; v; n9 V
  SetTitleMatchMode RegEx
, _( U" y+ t  L& W  return+ j, Q7 F, N* `  A! T8 `
  ; Stuff to do when Windows Explorer is open
) p& X' d. ]1 G! T8 L% N& n  ;$ Y- F0 H8 c" V! m5 ^
  #IfWinActive ahk_class ExploreWClass|CabinetWClass8 w+ a6 a' ?6 U. o
  ; open ‘cmd’ in the current directory' V6 J1 C, G7 w' G# U
  ;+ f( |2 @' V5 I+ s. N- B
  #c::
' p% e! t6 }  H  OpenCmdInCurrent()# P7 T" M/ h  }5 a+ \9 G
  return
) ?8 ^4 C: a8 _0 F( N2 h: g8 a  #IfWinActive
. j( V$ c/ @3 t. L  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.1 z% z' ]) n0 N0 ?$ a
  ; Note: expecting to be run when the active window is Explorer.
. X% u9 l& O4 V  ;
8 @" }0 F% e$ i3 {' x  OpenCmdInCurrent()( Z5 o  L- U- |# j% O* x# ]
  {7 l1 n1 ]$ f! v7 p7 K
  ; This is required to get the full path of the file from the address bar/ S, l% `9 \& q6 d' V
  WinGetText, full_path, A% R. e; L, M% ~; q- C
  ; Split on newline (`n)
- h  |) G" e" B$ P  StringSplit, word_array, full_path, `n
5 n8 _9 G+ Y9 L  ; Take the first element from the array$ j3 [3 S& V) O5 o6 w# W3 c
  full_path = %word_array1%9 @. ]' F7 E; \" e& r) M5 @5 I
  ; strip to bare address
. i/ c# s; I* e5 d$ ^6 `0 @  full_path := RegExReplace(full_path, “地址: “, “”)
$ x; @* ?) l; \$ D* c  ; Just in case – remove all carriage returns (`r)0 U" D  V) V0 E& x2 h' b# E# M
  StringReplace, full_path, full_path, `r, , all, I' M+ @2 D( o( A+ _
  IfInString full_path, \
/ r9 F) B3 W+ Q' J# b5 m; n  {; x4 Q4 _5 f  g) u1 V0 v
  Run, cmd /K cd /D “%full_path%”
0 n% V! {9 }. W' |; c  }
4 q8 @9 T8 }3 E! K' }4 a: r2 U( y  else8 ^3 H' M6 c, ?# B: W2 {3 Y
  {
8 L3 W) s! k4 o  U5 D0 b1 k1 b  Run, cmd /K cd /D “C:\ ”" T1 N2 C. G. E) m6 c& K
  }+ G" R+ i3 i' Z! C" `) f
  }% i1 o* \1 M# `" y
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
3 n  h2 V% O7 }" n  这段小代码肯能有两个你需要修改的地方
! Q+ ~6 M/ K1 [# H9 o% m- V9 w! s  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键7 r' x/ O( ~2 h1 o. u7 W3 }7 _  t
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “9 r; J9 j9 }& R9 H+ {; @7 E
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系我们|手机版|小黑屋|Archiver|电脑互动吧 ( 浙ICP备13037409号 )

浙公网安备 33032402001025号

GMT+8, 2026-3-2 22:49 , Processed in 0.057504 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表