电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
3 [1 K' _: p( B9 O4 l& R* H! x  `2 V: v  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
; a8 D" o; b9 w* k  方式一:
$ O$ M! ^  k6 t# J- U$ d, x1 b- p8 c4 Q  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,! L- `: c2 ]9 _2 M( b! p& f
  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
1 ]* t7 z$ O4 N$ v1 ^! n1 x, N. v; C  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
" ?4 U: Q2 u3 H. `  方式二:- |- V! V: m6 F% b) m. {0 w- p1 |$ }
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:3 O, R  A4 C1 Z* l" _3 v* A
  SetTitleMatchMode RegEx
5 N7 {2 v5 O8 d" D% C  return5 ~* H$ ?! t& t6 c9 D
  ; Stuff to do when Windows Explorer is open
; F' Y  ]' c# A4 b& l) L9 ?  ;9 L6 @* ^( P( u  M2 O7 n$ x! q
  #IfWinActive ahk_class ExploreWClass|CabinetWClass( _: r! n5 K/ t* c
  ; open ‘cmd’ in the current directory+ y' U: M) w  q' {5 k+ o+ N. g
  ;( H  h2 j/ r, Q+ k
  #c::( v7 ?' d) y' V- f: O" a
  OpenCmdInCurrent()- X6 D6 h; t. t# u3 j7 u1 }  `
  return
5 [5 M( Y3 t, ?$ x# j% u3 p) y  #IfWinActive; e7 \) K. ^( }- O5 [; J
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.8 o, B, v. ]* W9 ]% m
  ; Note: expecting to be run when the active window is Explorer.7 s: P1 G  w% j; I1 |7 w$ x
  ;3 T) d: g9 q* n  o, i& E9 {! D; H
  OpenCmdInCurrent(); ^: U: T& J& m; s
  {
1 O7 X7 I7 l$ D+ V' K  ; This is required to get the full path of the file from the address bar. v* p! j) _' M! _6 z
  WinGetText, full_path, A
1 L  q0 P3 S4 S: i/ L5 B; m3 X" v- o  ; Split on newline (`n)
/ g( e+ S# X8 E  P. F0 b# s! ]  StringSplit, word_array, full_path, `n) w) ?4 S( t7 }& m; O
  ; Take the first element from the array$ v& G' ]2 O) {
  full_path = %word_array1%
: G" Q* L4 f, L$ Q9 A  ; strip to bare address, A- c; P$ H* I+ e, J! e. W
  full_path := RegExReplace(full_path, “地址: “, “”)! c6 x! y4 Q; Z
  ; Just in case – remove all carriage returns (`r)- X  u# A8 Y& m
  StringReplace, full_path, full_path, `r, , all
% ?" s3 W4 d: X6 }" b  IfInString full_path, \
1 n# c% l/ ~2 f9 a/ P7 r  {
0 R; Q$ _  r; T4 R& h  Run, cmd /K cd /D “%full_path%”
+ D, \$ Q8 P0 k- Q, \" ^" H) K! F- z- o  }
/ G4 C4 {2 x, _5 j; F3 a8 T  else
& w5 R' s4 O% ^$ z  {! `6 R7 Y6 @, j3 n2 Z+ m- z
  Run, cmd /K cd /D “C:\ ”
6 ]; L' X. O+ B$ s  }
- K5 ~. _1 j! [" `/ Q' W  ?. e  }/ [9 J4 P, s+ i* s. n+ k1 N
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
3 ]5 l: y3 n; R  这段小代码肯能有两个你需要修改的地方: `  B9 x7 C' |9 T* R( |" r) m
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键; W  {& b8 S6 M* v
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
" {" i" x' n1 b: F# ]1 u
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-3-27 12:06 , Processed in 0.054732 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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