电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
) P) B5 b2 M2 d* R  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。, k8 B/ L  [3 m) n# Y
  方式一:, y4 K# ~0 F2 @- y
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
! U" S/ a# a. ?: z8 h6 `4 ^, S  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
; k/ w2 t/ N, {. y$ ?+ f  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
9 c, d0 y. T& a8 z  方式二:
% j. O) h& A# n  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
' V; S- C) Q0 `" z0 J  f  SetTitleMatchMode RegEx5 H6 J7 b( d$ Q: {4 k  e6 G
  return
. g. x% A# E' }" b9 V4 i/ l* l  ; Stuff to do when Windows Explorer is open7 j+ j) A; o1 V7 B3 f5 f# L
  ;6 F( B) S" u6 s1 h: N
  #IfWinActive ahk_class ExploreWClass|CabinetWClass
8 L6 F4 O& n  s$ L4 [  h) F  ; open ‘cmd’ in the current directory
& y8 e) Y9 }, O' h8 {5 D/ C4 ~  ;
/ y& ]# W$ l5 F# M  D" O  #c::7 B# ?; v, z6 M0 v3 Z& Q6 w
  OpenCmdInCurrent()) b. S1 |- I- ?2 O& ~
  return+ s0 |9 w. s1 Z) ?$ l
  #IfWinActive
/ J2 r) }7 B0 K# f8 `) f  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
6 i: L6 m4 N) B# O( `, U8 q/ C  ; Note: expecting to be run when the active window is Explorer.& ?/ T8 k: j' [+ x( |# z
  ;
5 L8 g1 u  W* c. p  OpenCmdInCurrent()
' B7 @3 Y# y( w) m+ ^; Y9 e- ?. K2 d  {
+ z- d( H0 N' Q; z  I  ; This is required to get the full path of the file from the address bar
6 F" H) P; f  q% \8 t  WinGetText, full_path, A
5 C8 X7 f, G" D0 j7 v  ; Split on newline (`n)
$ ~9 \  Q$ U2 P( w4 k. Z  StringSplit, word_array, full_path, `n
3 f4 J* I  ]4 [/ H  ; Take the first element from the array$ q  O: h* }$ P2 ?& B4 @4 T* A
  full_path = %word_array1%- J, T) C( D8 h% m) P
  ; strip to bare address3 U. N1 [% ?! ]( C  n" n) p
  full_path := RegExReplace(full_path, “地址: “, “”)
) t( c; R# ]" u/ w  ; Just in case – remove all carriage returns (`r)
& x6 G+ t0 Y. m5 J+ q! D3 P8 J  StringReplace, full_path, full_path, `r, , all. A* s& K, {, s0 s( C, m1 T
  IfInString full_path, \( K! O- ?& I  A" X: g
  {2 X8 g# E6 j5 l. D+ b
  Run, cmd /K cd /D “%full_path%”7 O/ M# j8 q  W
  }$ V* z! k3 Y1 s' h6 s3 {' L/ |3 f
  else
& e, m; ?+ `+ R$ r. P  {( Y- A' [9 M4 E0 }" B( _9 s4 t
  Run, cmd /K cd /D “C:\ ”) ]0 q4 a; V- a6 i8 g
  }
/ k/ L8 R8 t0 e: T6 `  }. r% O. F) B; R+ M3 O: Y& c0 _
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。8 k% F3 M$ w8 m/ D3 n! t- P/ e9 q
  这段小代码肯能有两个你需要修改的地方
% K9 M) Z$ G. j9 F* t8 |  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
# \# |* w4 C/ H+ N# F. i  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “+ ~# }" F6 ~2 f. J- a! T
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2025-12-8 08:25 , Processed in 0.086025 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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