电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。0 V, Z; R& ~) W/ i' K2 h/ X
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
- t  d+ R: X% v9 ]' ^  t  方式一:
- K( U. B: L3 c9 q. x' w  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
% E( ^* r; b! `% x" Y  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和! Z. I, f! C5 j7 `
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。- x, L5 e, {( i  t9 a! L  l
  方式二:( Y7 }* C' ^# @2 M. C0 g
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:: ]# l, k1 k+ N& B
  SetTitleMatchMode RegEx0 d! ]- P% f: I5 n
  return3 x: C8 ?. O1 A* Z" h+ c) |
  ; Stuff to do when Windows Explorer is open
7 x- r! H- ?) @* J& |0 J3 F0 ]  ;
# {, t' b: h" E8 Q" D  #IfWinActive ahk_class ExploreWClass|CabinetWClass
" ^) k& r! E) c* b2 n+ i  ]2 _: ?  ; open ‘cmd’ in the current directory" i* W; r% w7 y# p9 Y9 l: w
  ;
3 |+ g9 K3 W' R4 p6 Q( a  #c::8 X2 Y7 x* }1 q, d. q
  OpenCmdInCurrent()
  v% _* }- H( {9 J: h/ N  return
5 Z8 F9 A0 Z- s1 b1 l  P- {  #IfWinActive
+ w7 J$ F' I8 z" B  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
( ^5 Q! V, ]# I  F  ; Note: expecting to be run when the active window is Explorer.+ I: n1 W' o$ {, F* m% @. {1 H9 ?
  ;
' z( L1 ~( o! R4 }, }( }+ Z5 ?  A# c  OpenCmdInCurrent()
( f7 w( s6 W2 s  t* U$ z7 m2 r  {
0 B1 X% j+ G; h7 ]: y# d. K2 T5 j/ i7 E  ; This is required to get the full path of the file from the address bar8 n4 E4 g8 |. J* Q7 B: {8 l5 \5 {2 |
  WinGetText, full_path, A
+ x" y, a1 v. Q! t" A% H2 T  ; Split on newline (`n)
0 {0 X$ C* V& }- X4 a  StringSplit, word_array, full_path, `n: u- k% w3 ?. \2 V- K
  ; Take the first element from the array
: {* I0 e* a* Z/ T* `, c  full_path = %word_array1%. ~5 U  A$ E8 d
  ; strip to bare address
4 a- V3 n) G7 s" e" K5 N, C  full_path := RegExReplace(full_path, “地址: “, “”)3 P- V7 m' R$ x7 n/ C, I
  ; Just in case – remove all carriage returns (`r)
3 n& E3 r  u5 \2 e( x  StringReplace, full_path, full_path, `r, , all
$ R, m6 y4 n2 u$ m# V  IfInString full_path, \3 p, l0 ]: H" p
  {2 m. B6 K8 U4 y4 w& m! [' o6 x
  Run, cmd /K cd /D “%full_path%”
7 F* Q6 x4 _5 @! Z+ r4 O  }% t0 P4 r4 j$ i+ r' K
  else
* h4 H5 {& q, M6 e4 D: z! n  w" I  {9 ^, ~+ R2 K! p% ]1 f
  Run, cmd /K cd /D “C:\ ”
5 h* Y; {/ Y* B# Y* C  J  }
, }4 \1 b; W& G3 o+ l: d  }8 Y9 z! S& F  y- N$ v3 x" u
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。! ~# n) q# ]% c& w
  这段小代码肯能有两个你需要修改的地方
- Y$ X* O( v' u% H) [+ t  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
" a/ E8 |. m$ t/ b( L8 h  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
( {  F3 C& o1 S
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-10-25 00:47 , Processed in 0.088057 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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