电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。1 m$ _$ l! n+ s
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
- `& o$ _7 C/ o- U6 r) W8 W8 ~  方式一:
" l3 I5 q$ [5 W7 o- f# ]- ~. q  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,8 q% I$ x4 Z( m& r! L# F& ]
  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和# G  ~3 v* X) a* m8 I* ^* i: s3 k
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
: B, ?7 x' R% `+ z  方式二:8 P% Y5 V  s6 o6 w
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
" Z% |7 l2 Y1 A' t4 M1 h" k  SetTitleMatchMode RegEx
) W, s' J+ c3 \4 Q  return
# @7 k; y# t# \# u: @8 G) n' E4 W  ; Stuff to do when Windows Explorer is open
: E5 Q) |) \7 @7 ~  ;
: V) U- X' Z3 M- ~5 S  #IfWinActive ahk_class ExploreWClass|CabinetWClass5 A6 R* i0 z+ W8 z  `' T' I
  ; open ‘cmd’ in the current directory
% t5 h* g1 g/ m* r  ;
6 \9 ~% t) s1 L% T! G9 _7 a2 _5 W  #c::
5 {) i& [; h# n3 B: B. P- F1 o. w  OpenCmdInCurrent()
' Q7 c  }2 d% g  J& q' F8 M  P- J) Q3 Q  return
9 b+ q9 W6 f( h+ l9 @! o  #IfWinActive' v3 Z8 R( O: ~4 ~, J, b
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
7 y1 @5 Q0 S2 o# h  ; Note: expecting to be run when the active window is Explorer.
' \, u( Q* Y* j+ \: d7 Z8 W  ;. I0 A3 K; G8 f' I3 u9 ~' h
  OpenCmdInCurrent()
# y  v" ^2 K7 P7 @3 {7 h* j# }  {
8 R& U* ]0 k( ^5 H% x9 b, |  ; This is required to get the full path of the file from the address bar0 f; |2 e! J8 }! _4 Z8 p
  WinGetText, full_path, A
; K7 n- Y+ u1 Z  ; Split on newline (`n)
+ Y8 X' [) g2 e  StringSplit, word_array, full_path, `n7 p! n% _; j- D5 i" J% Q' a6 R
  ; Take the first element from the array
% `7 Z2 z; d0 P% p7 {. d/ d  full_path = %word_array1%
) @6 a6 g+ @5 u! i  |; A  ; strip to bare address
5 U5 B* U$ q* P8 h# }2 S  full_path := RegExReplace(full_path, “地址: “, “”)8 w( R  ?: Q: F
  ; Just in case – remove all carriage returns (`r)
9 M2 l8 _$ m( g: Z7 Y6 n) V6 I  StringReplace, full_path, full_path, `r, , all6 B3 P' N* S/ p3 _# N
  IfInString full_path, \
3 f  e# ^+ v4 E, s+ P  {3 N0 F. _3 B9 c3 F% n
  Run, cmd /K cd /D “%full_path%”
7 H& W( l( ]1 F2 u: u8 p  }
, S4 Q/ s( j' [1 o# E  else
, D- ~" m* [/ w  {
6 |% u4 S- D* T& [+ G  Run, cmd /K cd /D “C:\ ”
6 O, l% U( B/ c* L# c  }
% f  Z' b# G$ B" K- f( e: J5 J  }
2 F( B  f+ q: b* V' w  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。" \1 I6 \3 k% p5 X
  这段小代码肯能有两个你需要修改的地方+ l3 H; U" p% m" I
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键/ s9 c  z' ~$ w7 k8 A! H, F0 K
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
: w3 U; X  t% x( R1 K+ h# q2 I$ H
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-1-15 04:16 , Processed in 0.069513 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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