电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。# S- F! ^4 R# a
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。6 _0 ]7 u& ~4 B
  方式一:: ]# Z% V7 N) _7 |" Y1 B6 O) r
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
' F2 \6 x1 h7 j# I9 n# f! K8 ?  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
5 V* ^, m9 G/ a( @* _' M0 U3 P, y  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。( ]: v+ x% u+ ?' n
  方式二:$ u5 E2 {7 T6 d- V  ?
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:$ t* P4 B, s$ s4 F1 |
  SetTitleMatchMode RegEx
1 o# {6 j3 A  Z/ c  return7 e. s5 o! b8 ^* [  v7 O
  ; Stuff to do when Windows Explorer is open2 @! T. \( F8 ]
  ;
( u3 J0 i6 ~5 s% o- W  #IfWinActive ahk_class ExploreWClass|CabinetWClass. D& ?5 T4 |9 B' e6 ?5 w
  ; open ‘cmd’ in the current directory8 o" e- N9 F/ U! p
  ;
' W# B2 E. W3 S1 g* j8 P% k4 k  #c::* j( _* F: g" x, d  J; B+ ^9 @
  OpenCmdInCurrent()
3 ?- j; K% w0 `8 S3 r) T2 j& A  return
! Z4 G, Z8 G" a# ?* B1 b9 L# g  #IfWinActive! M+ ?/ G  V* C# o
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.- ], o0 }2 `1 `4 B4 I3 f$ N5 F6 Y
  ; Note: expecting to be run when the active window is Explorer.: Q8 f* n. {* Q: K$ w) U* [
  ;$ B+ Z" w# `6 e. |$ B% ~% L
  OpenCmdInCurrent()0 c: Y. J/ z8 v: e& \1 |# _% I5 [
  {
5 _9 x3 s; V. t) X! P# k  ; This is required to get the full path of the file from the address bar
" ^& x- _. r* v! N/ V9 T5 E  WinGetText, full_path, A
8 V7 j. J3 v& ~9 u# P  ; Split on newline (`n)
4 s& a/ f1 H0 M& u. T5 [) m  StringSplit, word_array, full_path, `n8 ^8 Z  e& t  k: v6 l6 v# q7 g
  ; Take the first element from the array3 ^" R, Q$ e0 o# K2 B! d# c
  full_path = %word_array1%3 M0 e* s( \3 w
  ; strip to bare address6 P5 |! T( t/ V. U: X
  full_path := RegExReplace(full_path, “地址: “, “”)
. A( m- U9 D8 i5 ?$ e* E3 ?7 D  ; Just in case – remove all carriage returns (`r)$ r. E( K; t7 m! K: Y3 l" d
  StringReplace, full_path, full_path, `r, , all
% o" T. n4 T' p# q, ~  IfInString full_path, \
9 c* U4 U6 t1 m5 L  {5 O& F! @, S" o$ e; l* r
  Run, cmd /K cd /D “%full_path%”' l+ B$ v$ Q) Q
  }
0 y2 g) U) Y! `3 n* ]: z* J! ^; }, E  else
; v4 U0 D% ~# y: S/ I  {7 v$ t7 U( V/ Z" _# D" D5 x- A6 U
  Run, cmd /K cd /D “C:\ ”
4 u) g5 T1 h+ j' ]  }/ x6 N: {5 A5 v& q! F
  }
* P' M! V: ^+ R6 \  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
+ V' g! I) ^  G7 ^6 V/ r  这段小代码肯能有两个你需要修改的地方. d* J% k3 [3 T8 T. }
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键8 O3 y; ^0 {6 O4 X  h9 C
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
1 V8 _8 a$ R8 E8 B  P' d7 ^
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-6-29 15:33 , Processed in 0.103703 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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