电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
3 P) H3 z$ Z" m2 f1 L- |  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。1 b  H' h9 b" h3 @6 |
  方式一:
. f# ^. ~/ j) |+ R- m+ A6 |  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
+ @, K& ?0 j1 Z2 d. W* }  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
5 d; p  `/ |6 m; _" ]  @' W  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
1 X3 B/ A2 ~( M% r# Q  方式二:
% ?% w: J9 S) j  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:) L# j! T5 r; T
  SetTitleMatchMode RegEx
+ o4 b( d, _  R' |' K7 z( N  return
1 g  t8 y& \" y0 M) z$ m2 |& t/ z3 l4 Q  ; Stuff to do when Windows Explorer is open
: A; h" y- \6 Z3 z: R  ;
" x0 I. {1 F* A9 N  #IfWinActive ahk_class ExploreWClass|CabinetWClass4 x* g8 P3 E6 S2 z7 Y- \
  ; open ‘cmd’ in the current directory
, ]' C* u  v# B; F% z2 Y3 @  ;! U* m8 W: a8 N; h. ?9 ~
  #c::
. @0 ?! V6 l+ M+ V4 W+ W7 z/ p, L  OpenCmdInCurrent()3 C3 B# p" p# R/ @- i& V5 B
  return
# x$ C" o1 O3 _( T6 m' C9 A/ e# @9 J# Q  #IfWinActive9 l' P: N7 @8 T  g8 X
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
. E9 G+ K8 v& E1 Q1 `5 F0 q1 D  ; Note: expecting to be run when the active window is Explorer.
; @. Q8 A- d) H( N/ {6 e  ;
3 ]0 {$ g4 |% `7 X" ?' R" a; ~  OpenCmdInCurrent()
$ e  G& r9 e! c  {
' W4 x2 z7 v. n. s- e9 u6 W  ; This is required to get the full path of the file from the address bar! I9 W) }+ C7 l( z2 s2 |/ [* u/ s
  WinGetText, full_path, A
6 O% g% S% o0 w5 |9 t+ K% Q* x  ; Split on newline (`n)
( w- D+ I. y4 D$ \% K% V2 P& B3 w  StringSplit, word_array, full_path, `n# i& Q, Y0 d  z& _2 _
  ; Take the first element from the array& j3 _$ Z7 Q$ _; w! l( i6 K
  full_path = %word_array1%
7 h. g% t  U2 O# z, @5 ?  ; strip to bare address
% Z) c' d- H* `$ b4 G# J/ ^3 q  full_path := RegExReplace(full_path, “地址: “, “”)- c. [9 B! ^4 @7 F4 C: j4 S; @' C
  ; Just in case – remove all carriage returns (`r)% ?2 O+ w, I% u9 W1 n0 b. T
  StringReplace, full_path, full_path, `r, , all
$ q- [) n4 d! d/ g9 u  IfInString full_path, \- }1 s4 F% z) \2 J8 G
  {
5 q. H' w1 m, k  Run, cmd /K cd /D “%full_path%”
" w' X, k! e9 i) }5 W, q! `  }3 u7 e, A$ t* P1 Z
  else2 @' o$ s* A* e. ?8 c* w
  {
$ l0 I) ]  ]5 d& T* z  Run, cmd /K cd /D “C:\ ”4 D) \$ O9 M/ X, L0 S
  }
6 o: j0 {/ o- W  }
$ t0 y+ w8 R( a8 q3 X1 `' k, e  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。8 j% r. k8 [6 H- n  M5 F
  这段小代码肯能有两个你需要修改的地方
5 M: F2 D3 G/ _$ R  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键! P6 l; t0 M5 j8 w* A0 A5 ~8 \
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
) c# _1 V) e0 P6 x8 B' M
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-1-25 15:26 , Processed in 0.060630 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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