电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。- g2 r6 O' i% l$ Y/ J) R3 M
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。/ x" D. F+ {) r2 G) w3 R, L# U
  方式一:+ q5 M( u" F# Z, d) z# E
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,, T* {; R, a( T1 ]
  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和8 h1 a: ?# Z7 Q* h+ |8 e1 D' }
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。, ?7 Z2 o: e0 c+ I$ x1 m+ U
  方式二:
7 E( H+ M0 s& N( `8 n9 r  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:2 ]) d% {- V# @; d. R0 e6 M
  SetTitleMatchMode RegEx& J3 j+ }; z* v: O% E& @3 H, Y' _4 p
  return0 u) d0 S) z: r* I
  ; Stuff to do when Windows Explorer is open
& d& r+ x' g, K( M, W, ]1 K# Q6 W6 ?  ;7 n, k2 N. w0 E1 |
  #IfWinActive ahk_class ExploreWClass|CabinetWClass+ I# T; e4 d9 O7 w# P
  ; open ‘cmd’ in the current directory
2 c8 t- C8 d) ], L  ;* Q  W# Y  n# R
  #c::! K! ~3 C+ z: ?
  OpenCmdInCurrent()
( P9 q+ q* g# V% v# q  return
: Q- s' u0 R  ]' N4 d  #IfWinActive- Y# n+ J# O" _
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
$ N* y- ?6 G4 l+ o  ; Note: expecting to be run when the active window is Explorer.
, _# M/ ~' n0 v  ;
7 _1 o& j; Q! p$ [5 \/ e/ K  OpenCmdInCurrent()/ Y. o2 G7 a5 `
  {" e6 Z0 Z& ~  P/ A% y8 e
  ; This is required to get the full path of the file from the address bar
1 m7 J' \0 I# F5 T, R9 P( ~  WinGetText, full_path, A
' e- }, T. E/ I$ x5 n2 Q' l4 T  ; Split on newline (`n); r+ X0 T1 _* L* K" b4 a" C
  StringSplit, word_array, full_path, `n5 H! v, g- ?3 b% h  Y# ~1 A
  ; Take the first element from the array( j. a! n( N+ F. Y& R; a# Q3 \) ?- K
  full_path = %word_array1%+ x9 Z+ o! W8 ]5 V3 i& x9 I4 m* g
  ; strip to bare address$ P% o2 f1 k8 ~: Q& V( V
  full_path := RegExReplace(full_path, “地址: “, “”)
' X3 S; E5 p4 f# d7 x) X: {5 O  ; Just in case – remove all carriage returns (`r)
, B" A7 {, n0 t4 y$ H  StringReplace, full_path, full_path, `r, , all
4 m5 R5 L+ O/ J; A( s( V* `7 W  IfInString full_path, \
/ d3 B$ k& u  S1 a" p  {) v, a; p* ~/ q4 ?3 ?
  Run, cmd /K cd /D “%full_path%”
4 }; q% R- T: j& p0 L5 U5 I7 B  }
/ a9 A% S, U: F' D1 `# {' P( C  else& K; @; l' G0 P6 A( E9 v/ l5 j
  {
7 U* y& b6 L. Y. s. R/ \  Run, cmd /K cd /D “C:\ ”
. y3 U! n* Q3 b7 s* `9 J  }# s) c; ?9 E) R7 C$ K; y" ~2 D
  }- p0 a7 W- S/ ?0 D4 c: k3 J
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
' u8 K' ~# }! K( G' @& _7 Y  这段小代码肯能有两个你需要修改的地方; {" K& t; v, W0 D* }& D
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
: b7 N, i4 ?9 d, f& I! I: i7 t  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “- V& ~0 d5 t: \; ^+ n/ P
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-9-19 20:35 , Processed in 0.061875 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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