电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
, m+ P8 B9 s* H& \3 W# l) }  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
; D0 i8 D, f+ o1 r  方式一:6 F9 c, {' R0 a" S3 s) r
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
2 L$ L5 N' n( W+ H1 I  ]  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和7 N+ }2 e8 k) U  J
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
$ p7 v( Y2 D: j, f  方式二:
! ~* K1 q! A" t& Z, A. E% P1 J/ F  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:3 J0 [0 |# ~, {7 a
  SetTitleMatchMode RegEx
$ h' J8 f& k' G1 T2 f  e4 g  return3 l4 ?9 p- y, |2 m, P) {- ?; Q
  ; Stuff to do when Windows Explorer is open
0 C  F" i: p/ D# o( F( \  ;
/ A& _/ k; l2 f. p. m  #IfWinActive ahk_class ExploreWClass|CabinetWClass
: n) [) t( m; M5 {! B% x, P) J  ; open ‘cmd’ in the current directory3 u- R6 u/ p8 \# ~. s* L- t
  ;
6 g+ y) g! S; Y0 t  #c::
- t' Q" \; x) Q  b5 A1 e  OpenCmdInCurrent()
% c/ g( n5 E1 _1 C$ H, I- ?  return8 G, ~. Z! S( _; C# r9 c# K
  #IfWinActive
( G# x/ n0 j7 J  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.3 n3 B+ w+ t3 f" ?; ~* o8 c
  ; Note: expecting to be run when the active window is Explorer.! I3 m8 s+ }) h8 U# i
  ;' f+ K% |9 W. A5 M: Z2 o( @/ ?
  OpenCmdInCurrent()
& r( M" Y7 Q, @4 F, N/ Z  {- }% Q# U, ~. l. x* R; K  S+ {
  ; This is required to get the full path of the file from the address bar+ Y4 B& F& c; K( s  Z; y) f
  WinGetText, full_path, A" ?7 m9 \3 K' b; h/ ?; R0 e
  ; Split on newline (`n): R9 S; f4 ?% Z$ @* g
  StringSplit, word_array, full_path, `n
- W" |3 A: n5 ~. I4 ]3 u: t  ; Take the first element from the array
) I- ]  V) t, \+ }1 ?' E  full_path = %word_array1%, e% @! d, q( V5 u) f9 w
  ; strip to bare address
; l1 i# G( `; t: C4 h  t  full_path := RegExReplace(full_path, “地址: “, “”)
" \3 M$ w/ p  ]  [  `, u  ; Just in case – remove all carriage returns (`r). ~4 ~% B( q$ r! b- K
  StringReplace, full_path, full_path, `r, , all9 p: j: v! K; ^: {
  IfInString full_path, \
, c5 \8 L+ W+ M, X! n' w( O% @  {
8 p" |8 r, T2 r+ w( n% |: p6 \, j  Run, cmd /K cd /D “%full_path%”* @7 n: L# [+ x& p0 Y) G/ |6 v* N
  }% I. c* T1 k1 a: h1 F9 u- |
  else
( [6 \6 {1 p: G- Y6 u  {/ H/ n5 G% r* X- H
  Run, cmd /K cd /D “C:\ ”7 m5 w! q. ?+ t8 E  |/ P9 i8 j
  }! [# {) G8 ~. O1 c) c5 j
  }: h/ c7 Q- h( W2 {9 w$ i1 x
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
! E8 y( S. m8 C( f0 l' e  这段小代码肯能有两个你需要修改的地方& C9 L$ o4 x% b" l& r! q7 l
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键, |& h8 f' U, |3 F
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
2 h( a2 @) t) ^1 [. w6 L* s
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-4-6 16:43 , Processed in 0.127096 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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