电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
% |) S: _2 ?7 T; l  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。1 h8 e' P; w6 h6 t2 S7 a1 M9 }
  方式一:/ j; D1 b, y  a& b( T+ W
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
7 V) y( U1 y% P7 Y/ e( ?  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
/ O( a# v8 V4 J3 W5 O  k  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
$ ~* t; U+ f2 i  方式二:+ B/ M" S7 H: V6 O1 B
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:. M( j' B2 E1 \  [
  SetTitleMatchMode RegEx- [5 ~3 r; X$ O9 X5 M2 j$ J
  return
* H, m" ?( B! c  ?% H  ; Stuff to do when Windows Explorer is open. o5 L& @: ]+ r' g0 `6 ~
  ;: x5 f0 ]8 c: T% l/ g7 Y; m
  #IfWinActive ahk_class ExploreWClass|CabinetWClass: y" f; h) p9 H$ Q* ^) K) Y2 o
  ; open ‘cmd’ in the current directory! E& H2 _, L. H! B- ?( w
  ;/ Q' E& X0 S2 ^4 t3 ?4 o+ a7 L
  #c::
; C, E1 [; f% i9 k  OpenCmdInCurrent()
7 p$ L3 _' y0 U. N& r, c$ Y  return
6 M2 [2 ]1 k% b4 k1 }- e( P) {) T  #IfWinActive
  y, N+ i+ C0 V) t5 v$ ^! b  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.- p6 K, F# q( k# d2 r4 T
  ; Note: expecting to be run when the active window is Explorer.
9 ~, Y3 c) n9 K" x  ;. f8 x9 v; F$ R
  OpenCmdInCurrent()2 z6 Q* I. S9 D
  {* n) v+ x; z3 E* W' I
  ; This is required to get the full path of the file from the address bar3 X- Z0 s2 L( j. N* ~
  WinGetText, full_path, A: O; D6 g# S, j# N
  ; Split on newline (`n)0 p; ^2 O; ]/ H  L3 X" }& o, j' `7 P
  StringSplit, word_array, full_path, `n  j: S0 t# W) C( s8 `! e* f7 m* m) C
  ; Take the first element from the array
# X1 |  X, |9 q1 ]- B1 R  full_path = %word_array1%
2 ~% u1 O5 N- O4 p$ ]  ; strip to bare address; k: _9 H- s$ ?* b: ^5 j/ t7 m3 z# z
  full_path := RegExReplace(full_path, “地址: “, “”)1 |* l2 O' x1 g4 P! U5 ^
  ; Just in case – remove all carriage returns (`r)5 P$ f' n3 Y, T+ v' s* O
  StringReplace, full_path, full_path, `r, , all% C1 R0 N+ S4 b7 q! d
  IfInString full_path, \
1 S- \8 I: `9 {5 s5 ~( A  {& Y3 h0 b' [7 x+ L, J
  Run, cmd /K cd /D “%full_path%”6 }, l5 T! X- m
  }% p6 a. A7 Y1 v3 I
  else
  z9 Q) Y4 G" h) M" L  {6 d2 C6 D3 s( E- s$ x; m( e
  Run, cmd /K cd /D “C:\ ”$ d! W# L( t6 m" ^2 a
  }$ D8 f+ P; Y7 ~* }
  }$ g0 M# V/ O9 H. L. n8 V
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
9 t8 m. o6 s3 |2 A  这段小代码肯能有两个你需要修改的地方
3 B/ b  m5 `5 n: ]8 E* _6 p  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键% _7 \2 Y6 }% M  h
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
& Y) A% m1 b" L
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2025-12-28 03:16 , Processed in 0.053181 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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