电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。" @1 e! r$ n. Z' L  g) J% X
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。$ u6 R+ B% M9 x) j
  方式一:
+ {1 ?8 d, N/ t  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,4 b- w8 V  M# f4 K+ _: G
  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
* |9 ?: J8 y: }8 Z( B& L1 |  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
& z2 o" t/ E8 M' o4 S  方式二:4 e! U( |+ i( l; o5 s' E8 s
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:5 X- F: q; k) d3 u  M: ^
  SetTitleMatchMode RegEx6 {: ^) w0 o# ]+ n- G
  return, l6 j; Q' o7 P0 n' ?, J  X
  ; Stuff to do when Windows Explorer is open- R- m2 H4 s5 L- t5 N
  ;
1 s+ C: }) ]7 J7 Y. I  #IfWinActive ahk_class ExploreWClass|CabinetWClass
. h# i3 o! x: a3 k9 D  ; open ‘cmd’ in the current directory1 @- D# l1 b, R6 A
  ;
: H) m& m+ c& E# z  #c::. ?, y1 o- f- L: [) T% x
  OpenCmdInCurrent(); Q9 e) z) E7 ]) W# Z1 s
  return
8 e3 X' v: @# f* B5 i* y  ?1 [  #IfWinActive
  D' F3 _, w  @& M9 e9 @  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.! J% H- e" H, J
  ; Note: expecting to be run when the active window is Explorer.
$ n# G8 J3 Y1 a  ;6 u4 b( a8 {' q+ h' C
  OpenCmdInCurrent()
$ i" c9 x+ v  G- k" t  {
, w5 \* m$ b$ ?: Y; _  ; This is required to get the full path of the file from the address bar/ o& ^; ~2 D2 N! M- T
  WinGetText, full_path, A
$ \: D, A; @9 D) N1 n2 y  ; Split on newline (`n)
. K% N7 p* q  n) j7 k& w! i& X  StringSplit, word_array, full_path, `n
, h2 C6 e" r9 |( L0 Q  ; Take the first element from the array# F( E/ s% r: ^
  full_path = %word_array1%9 Q2 ?6 z% n0 k2 r3 S
  ; strip to bare address
1 V& W  Q! ?, b4 k. v. v& ^, T4 \8 k  full_path := RegExReplace(full_path, “地址: “, “”)& S( V% w" Y9 ^  W0 i  ?) c/ @
  ; Just in case – remove all carriage returns (`r)
0 C2 g7 z& x2 m; H2 ?  StringReplace, full_path, full_path, `r, , all  o& q/ D, x! S$ H, A, M
  IfInString full_path, \
+ g0 m! @9 }5 ~2 D! D  R: e  {
( _7 x: E. I- o9 T0 a  Run, cmd /K cd /D “%full_path%”
/ U! n2 u9 N' |$ }% Y, ]  }
- A' }; D4 B- h5 I- h  else
% P* z& G  R+ V6 m( d1 I  {( C  U. @* X9 f  e! `
  Run, cmd /K cd /D “C:\ ”( P6 r1 i  W( e% L
  }' D+ h" s" [/ e2 v9 f7 z* t
  }' A3 g- T) e+ P. h  B9 m+ {$ }
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。- y0 b4 ?' S; t5 k# c
  这段小代码肯能有两个你需要修改的地方
$ C, [+ F- k/ f$ L& i  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键# O2 Z7 E4 A3 F
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
. ~' f5 ~0 \% ~* |, W+ O' q) t) {
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-4-17 18:13 , Processed in 0.055351 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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