电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。5 T" u0 S1 w: M2 Z/ ~# M* r' ?
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。1 N3 S+ D- t- j* n! ]$ M6 N% g- @
  方式一:
2 @0 s$ G" V+ V4 m  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
8 c% }. w# x! Q3 S# d  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和& ~1 Y# y) E! r6 z- J
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。! ]3 @( O  w. O) S0 E
  方式二:6 X3 y: E8 A5 t1 H+ }9 X1 d( ]
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
: m; k! m) b. ]0 N4 h- X  SetTitleMatchMode RegEx
5 |6 |2 R8 m3 h5 l. p* g$ r" k1 x% j' y  return
( z0 {# z' P" S+ q8 H. H  ; Stuff to do when Windows Explorer is open+ P4 A! C: i" r4 r! [1 H# C
  ;
0 j! X+ R4 Y0 h& M5 [, E+ [% ~  #IfWinActive ahk_class ExploreWClass|CabinetWClass2 Y' Q* K4 b5 G1 H2 G  t
  ; open ‘cmd’ in the current directory
5 V( P, v6 y: e* R- L/ @: a: X2 b  ;( w! j% p: f% ^4 ^1 p
  #c::
& X& R9 m2 ^3 M" v9 y% O  OpenCmdInCurrent()  G9 D. W! S, m$ Y
  return* W, R6 A5 ^8 k' n4 o
  #IfWinActive
! E. m; D( y/ G, c  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.6 N0 D: {; W1 }5 P5 W; s
  ; Note: expecting to be run when the active window is Explorer.8 D; M# `+ ~! L" F5 @' c- K5 @
  ;! b8 e4 o2 O3 Q. A% h0 C2 @: Y
  OpenCmdInCurrent()0 [8 R. ]) j1 E
  {
$ I( k6 K0 P' ^5 `  ; This is required to get the full path of the file from the address bar
+ _; p6 `$ j& O+ v, {# B4 h  WinGetText, full_path, A1 e; Q5 o" i1 s' P2 N  _
  ; Split on newline (`n)& K0 l5 D- e% _- _' o5 [! [/ a
  StringSplit, word_array, full_path, `n
, ?" _( S  ?/ \6 W- s) _  ; Take the first element from the array
+ ~1 Q; Y3 a7 D; Z& h, {$ z  full_path = %word_array1%" }; O: P3 n0 Q% }, f
  ; strip to bare address& `% H) Z4 u7 C8 u, \# l3 l' Q. r
  full_path := RegExReplace(full_path, “地址: “, “”); U. Z* H' n6 @9 o, L7 a4 e
  ; Just in case – remove all carriage returns (`r)% B5 l: i2 M1 }# P
  StringReplace, full_path, full_path, `r, , all9 p" u4 O* j  w3 M9 E* M5 W: t
  IfInString full_path, \
5 E" x+ J1 d- N* `  {- Q* x! N$ }) Y- N
  Run, cmd /K cd /D “%full_path%”! ~4 D# u/ z  u) }" G
  }
$ `- {. Q7 o/ M% I- i9 u5 x( i  else
. W- i- D5 H' h& X$ C  {
7 C8 g" i  ]2 N3 [+ G9 f  Run, cmd /K cd /D “C:\ ”' _' Q% [! n! ^/ M$ x; L1 @
  }
" o2 F! m9 ~: P* u  }
' W5 }/ n: B; e/ ?  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。4 R- o  g4 u+ h6 G
  这段小代码肯能有两个你需要修改的地方
- k4 H. n# w, `. j2 |- f  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键+ f3 \! j5 J! m$ U+ A: h
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “% P: M) A0 q0 A( R; ?' N
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2025-12-30 14:27 , Processed in 0.084875 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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