电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
: m# g+ i% T! ?, e. x! C/ ]  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
' }. a# {! G# g/ \  方式一:/ i$ U+ F* y+ N& J8 N$ m* C
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,  Z( a+ N3 x% H8 ~# k; M& ?
  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
* S% m2 x/ k8 c8 o  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
3 x/ L5 |) n' ^8 r, i6 i1 _' X  方式二:, z! Z; F5 j" J
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:6 v2 Z. [' K# u* U
  SetTitleMatchMode RegEx7 p' t" [4 \7 Q
  return" Y: ^6 ?$ _+ _$ P+ s$ W$ l. e
  ; Stuff to do when Windows Explorer is open2 l- ?/ q) b: ]7 n+ {
  ;3 i5 w, p  J) ?5 ]- L6 U  x
  #IfWinActive ahk_class ExploreWClass|CabinetWClass' }! G& N8 ^6 E- R$ G8 ]
  ; open ‘cmd’ in the current directory
, @4 I+ X( a- q( P0 A2 h9 I0 g  ;
- Q# d( N* I) Z4 ^2 Q0 C  #c::1 k* O& J) L) v! Q1 P
  OpenCmdInCurrent()9 K& J. g  `% w0 l" [- C  |
  return$ ]( h" ~! T; n$ m" M- m( K
  #IfWinActive
) x+ h3 y: ^9 _2 D& i1 N% B  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.2 D! T7 h, N- O7 U4 I8 ?" t, w
  ; Note: expecting to be run when the active window is Explorer.9 w9 B% L# C; g; o
  ;
2 o8 n) y- [  F3 N4 m: M& }" N* @  OpenCmdInCurrent(). z7 s) S& f3 X7 {
  {. D8 G% F+ T5 }3 n1 i- G0 [
  ; This is required to get the full path of the file from the address bar
0 Y. ]% B6 e2 g9 P/ O* Q  WinGetText, full_path, A7 {8 d* S8 s, a0 M0 F
  ; Split on newline (`n)
3 E6 a1 [- V& k  F9 k  StringSplit, word_array, full_path, `n
' R) C: c) q5 D: k6 n1 U3 S  ; Take the first element from the array
2 f1 y& U! x& d$ P! q- l  full_path = %word_array1%
$ H7 T2 w& X; u- }2 e# ~- m2 R  ; strip to bare address9 n7 Z6 P1 G% O1 j  k" F2 \' t
  full_path := RegExReplace(full_path, “地址: “, “”), c# D, E; }2 ?" \7 B
  ; Just in case – remove all carriage returns (`r)+ w" N9 g" n% ]7 X6 U) h; @6 h
  StringReplace, full_path, full_path, `r, , all$ V# p! n) [$ X# C0 C; h" v
  IfInString full_path, \! {7 p- d8 X5 B! h8 }% n0 a
  {* C! v- y6 f4 V
  Run, cmd /K cd /D “%full_path%”2 D6 ?% V1 j) F
  }
2 t6 d- z, X8 ^/ [% C3 G  else5 |3 }* z+ F' |4 C
  {
1 l- h! o& K: I% ?; X  w5 P  Run, cmd /K cd /D “C:\ ”; M$ z& v2 y5 F: Q5 N! _
  }
9 i0 K. R1 n; c2 B  }3 |& J8 J. `; \8 ]7 X' U
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。4 q9 p* y: V! |* Y
  这段小代码肯能有两个你需要修改的地方& U) ]& {" ?5 E2 N8 \
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键1 X: A" |& B# q% t) W8 \) _
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
7 s" l. j# t1 @# p" ^8 J
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-4-22 11:07 , Processed in 0.120778 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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