电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
1 {1 H; s/ J& f  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。6 O; [$ B: `7 f  U3 G$ M
  方式一:2 I0 d; ^- d) T# c
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
: `, Y$ O' V. V9 _$ X  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和/ r) |/ K( S4 m$ B1 v
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。0 ]; v% S+ g7 l9 ~* W
  方式二:
2 c; y( c2 A! [  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:+ B# O& {4 g, ^& H( y( q# ]
  SetTitleMatchMode RegEx
/ N7 L! M0 x2 i$ i  return# ~1 M% C) d4 z- r% a7 ^! y: P
  ; Stuff to do when Windows Explorer is open+ {7 n! q- ^8 V0 y7 \5 S
  ;
  k$ }$ a8 g5 L8 f* x  #IfWinActive ahk_class ExploreWClass|CabinetWClass4 I; x$ W/ b  C) R9 h5 y
  ; open ‘cmd’ in the current directory
  j: c$ {  a) q7 B( B6 O  ;& F9 {8 S( I- f
  #c::
5 Q4 S# j! M2 ?( H  OpenCmdInCurrent()
2 a# n8 ~, D& F6 I: s8 j  return
, a) S, O6 u/ A/ }2 V. S. B  t  #IfWinActive
' R3 L$ h+ ?3 E1 I  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
6 @4 w: M# ]# \: i4 ?1 K1 ]( h& k' ]  ; Note: expecting to be run when the active window is Explorer.( B$ F% m" ~. _2 K
  ;  W4 w0 \9 O. Z: R: s& J: y9 c- \
  OpenCmdInCurrent()
, m& Y  r/ E, @) B( W1 i+ ^$ J& g  {; i* {3 i' o; P$ ?1 N
  ; This is required to get the full path of the file from the address bar* P5 G5 [. u* A) t; G
  WinGetText, full_path, A
4 ~2 O) g& _6 q  ; Split on newline (`n)3 D& ], \- S5 G4 F& K9 L
  StringSplit, word_array, full_path, `n7 g4 ~: f$ I, i# Q# B7 X0 i* P
  ; Take the first element from the array
% m$ ^9 p+ s, z0 X5 ~8 ~  full_path = %word_array1%
9 h7 W9 V6 N4 o$ g6 Y' _$ K  ; strip to bare address/ ~. M$ N! L, Y' e/ i- Z( V* X
  full_path := RegExReplace(full_path, “地址: “, “”)8 t& S6 v) z9 c) \
  ; Just in case – remove all carriage returns (`r)) |/ J9 h; \  j& k* s
  StringReplace, full_path, full_path, `r, , all
/ W/ U1 q/ m9 ~: b; s  IfInString full_path, \2 V& [4 G3 u$ Q. F4 u8 q
  {
- t) H& S! l7 e. u. Z  Run, cmd /K cd /D “%full_path%”
1 N( V1 V# ?0 A# w. l0 S  }
) f" v" W) K; Z, Q8 V7 A  else
: K+ r! |- L$ C+ r  {$ T/ e! W% ~9 ]  B5 O. W, Y( O
  Run, cmd /K cd /D “C:\ ”5 D; N/ ?; ~$ g) N3 @+ i" V$ X
  }+ m1 N3 s+ c- {. M2 ?# p
  }3 O2 x) Q2 k  l0 t9 a5 v
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
3 O) X+ r& E8 c0 O, K  这段小代码肯能有两个你需要修改的地方
& `' b# ?6 e  R# D2 Y% d  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
( c0 f2 k( g) V! V  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “+ R; P4 ]! X. n6 H* J
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2025-12-20 14:06 , Processed in 0.055537 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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