电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
" B- c6 N, R# `# g, b  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。$ \. y' C  p1 r: e
  方式一:
9 @% c4 c8 r# p. c: V% Q  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,4 b2 n9 {# l% @+ H- D6 q
  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和# C' J; M3 j6 S
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
- e0 ?% S9 ~! T; `0 j  方式二:1 A  H; u4 l! d8 J! k- ~
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:6 @2 M1 K+ n/ P
  SetTitleMatchMode RegEx
5 R, f7 A+ t& \3 y* W  return
/ E, B& c* f9 Q( q7 h  ; Stuff to do when Windows Explorer is open' R. A& J' n* g1 ?; X% g& Q' _2 S
  ;
6 q& `9 C* I6 M8 ~  ^( ]$ T! K  #IfWinActive ahk_class ExploreWClass|CabinetWClass! j5 l  {+ a2 O3 q5 D
  ; open ‘cmd’ in the current directory$ V8 J% n" ~+ v0 j. i
  ;
& y7 m8 M2 }: D' o) Z6 [3 L  #c::% [4 {7 ?) Q, R/ S* I2 ~( O
  OpenCmdInCurrent()
) H4 L7 }  M* o+ W  return
" K5 {  R/ Z7 A8 U- I  #IfWinActive
3 v6 g6 t" w) I( q) C; ^% X  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.; O0 @( _' `/ v+ w" y  ]% e' h
  ; Note: expecting to be run when the active window is Explorer.
0 S% _2 f3 g' _2 y; Y: ?: m5 J) y  ;) [, P3 S# h6 ]7 `; y$ E
  OpenCmdInCurrent()9 ^8 B1 `- R( ^7 j6 K# {
  {4 m; \3 [) }1 H& ?; b! `; n
  ; This is required to get the full path of the file from the address bar) d: @0 ^) J# b& I! z$ X
  WinGetText, full_path, A* W; G! n6 [0 z- S7 n
  ; Split on newline (`n), q; T3 C/ i& Y/ ?0 O  K# G8 j
  StringSplit, word_array, full_path, `n
! a$ s' H; @' n+ f/ ^+ d  ; Take the first element from the array! g8 P% {! M  g( W
  full_path = %word_array1%0 a* `3 j0 m! }
  ; strip to bare address
8 s: e4 Y3 M' o( K8 Y& Q6 @' D0 \  full_path := RegExReplace(full_path, “地址: “, “”): R3 n; p2 P, r2 S  L
  ; Just in case – remove all carriage returns (`r)% H/ t% ]# X$ Z$ H
  StringReplace, full_path, full_path, `r, , all8 z( z4 ]3 Q, j% \' i+ p2 Z
  IfInString full_path, \6 I6 Q. X  Y4 u, E3 K  Q" S
  {
% N. O) e" P# ?0 G+ O  Run, cmd /K cd /D “%full_path%”
) k: r6 I3 c) v. n* Z  }- R8 P+ o  ]) L6 ]
  else
. T, u  }1 ~; k, k7 E  {4 f$ \2 A8 Y9 i4 Z0 a1 x9 b. [* b
  Run, cmd /K cd /D “C:\ ”
; b# w7 V9 J, ], E  t, j0 Z* G  }1 i8 K0 {$ _3 v; U) [
  }
8 M6 U8 {1 {# J3 I; T% z3 s1 @0 _  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
( S) e* s. _% [2 M  这段小代码肯能有两个你需要修改的地方0 V& A* k/ {7 n- U5 }/ Y+ |
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
, P8 f  s& `( g/ G8 m  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “4 J, h% W/ d' V) J& B
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2025-12-5 10:12 , Processed in 0.118869 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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