电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
5 Y8 H$ O& m  G+ K2 f  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。6 Z  b2 h) I: _& M2 p& ?; M
  方式一:
* }3 v8 e' b# e1 x  C, N  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
" o/ w7 \1 D. Q3 N  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和; \3 T+ O( i& G+ p- s
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。0 i- F$ D! f" I# a
  方式二:
' d- ]+ _& Z$ \  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
9 Y$ ^, f/ b2 g5 _$ w7 k  SetTitleMatchMode RegEx0 ~+ D) @6 D* O. p1 S
  return
: f+ l4 a2 N, t( T! v  ; Stuff to do when Windows Explorer is open1 k3 P; `5 R2 z' N! p$ ]
  ;
# W/ O% D+ |2 Q) _0 Q7 t  w& e  #IfWinActive ahk_class ExploreWClass|CabinetWClass! J, h' O& ~* X$ o2 Q/ n" D
  ; open ‘cmd’ in the current directory9 r$ `) A: W- C% d; _1 Q% _
  ;
+ f; i+ C# y- i, W' R. a  #c::
7 V7 x* @: _% N1 \8 |3 d- X: o  OpenCmdInCurrent(), O6 A4 `# v1 N
  return
9 V4 n) t$ e0 V* [" c! W5 W: ]  #IfWinActive
! v, V8 ?) O$ [% Z2 b  V  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer." v+ j2 P# Z) q/ E
  ; Note: expecting to be run when the active window is Explorer.
- |. e9 P1 d, t0 X3 T. Y6 ]  ;) u* j+ |# P  ~- h, K3 |* h
  OpenCmdInCurrent()1 u5 @& G- o. i1 R" l$ R
  {
  H6 g: Q7 b0 N5 m  ; This is required to get the full path of the file from the address bar0 |; K) i1 ~1 @" v4 h+ o
  WinGetText, full_path, A' m. p: R; m% J/ E
  ; Split on newline (`n)& E" j2 [8 c2 m$ r: P9 n
  StringSplit, word_array, full_path, `n, U8 @7 ^4 y3 U3 `
  ; Take the first element from the array
- s. |7 |" P  L  full_path = %word_array1%
. @& t  A6 O4 m) Z3 e1 j  ; strip to bare address8 G" b) F) e+ b! [  d# M* V
  full_path := RegExReplace(full_path, “地址: “, “”)6 B5 `: c6 w* L/ S" H, ~3 f4 @
  ; Just in case – remove all carriage returns (`r)- k. W. o  m( t2 d7 y% |/ X
  StringReplace, full_path, full_path, `r, , all; V8 A$ K8 {. Q" m# o: s5 d+ C
  IfInString full_path, \
5 o* k1 P+ M% f: P% ?  {( \' D5 ^( L9 e% T* k1 H
  Run, cmd /K cd /D “%full_path%”
) t' X/ S# W& U0 q8 D; h  }
) [3 O, X8 _* W3 }* }* D  else. s2 D7 D) q" c+ ]2 E9 D( u
  {, t2 T9 H' J4 Y. C2 b& \  N
  Run, cmd /K cd /D “C:\ ”: v6 l. M7 {9 U
  }
/ @3 S" k; G8 e4 X1 s$ s  }9 u0 Z4 X- S% ]$ \4 v8 j
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
& h- n( ^) i  ^  这段小代码肯能有两个你需要修改的地方5 g8 F0 @# P& E, c, j) l$ ]" m
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
4 T2 A7 e4 {# _) d2 l  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “6 \& G8 b2 K0 C" u: n4 p: `
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-5-8 10:15 , Processed in 0.054659 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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