电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。; m" Q+ V' w9 h( W
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
2 _9 I9 x$ f. s9 O. s. d+ V2 A  方式一:
% W, G0 w! \& Y  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
4 Z& N2 o  B) L4 ?; V  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
8 c, }7 u$ y% |7 Y- x  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
6 @2 [$ I) n- N) @( e  方式二:. M+ m/ K9 H7 T4 p
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
- X% x. h% M* Z3 z# z  SetTitleMatchMode RegEx
3 R7 b: I- O0 U9 {2 M  return4 v2 O, _# T, R/ l3 D8 J
  ; Stuff to do when Windows Explorer is open# Y, N$ D0 \9 f  u# n
  ;
. V2 g3 e7 y2 z  H. f  #IfWinActive ahk_class ExploreWClass|CabinetWClass9 {5 ]6 |# n- R) q7 f& Q
  ; open ‘cmd’ in the current directory
2 e, L1 |. z# d  k6 L8 Q( I  ;( Z9 G- M! l) g7 d1 f/ |' n' l
  #c::
& F9 o6 x2 |. ]9 ?' N/ @: h% s  OpenCmdInCurrent()- ~, H) I$ n6 y$ ~
  return
  Z3 Z1 u% @8 z# ~' H5 b' }( o  #IfWinActive, a/ z* k* ^. q* K8 E# m" A& P. w
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
2 N( e5 z) J! B. H$ w( Y  ; Note: expecting to be run when the active window is Explorer.' y  K1 @: v9 H$ ~- _1 l; v
  ;& y2 D- b' m0 W' }- h
  OpenCmdInCurrent()& i) s! n6 E* h* C
  {
$ ?9 d. N* m0 O# r7 S  ; This is required to get the full path of the file from the address bar
6 s- l+ d6 q. @- x& L1 q0 ~0 j' c  WinGetText, full_path, A7 O  C+ O7 D5 T# i" ~7 {3 }, p
  ; Split on newline (`n)
3 i* Y6 Y; E7 j$ A9 i2 v  StringSplit, word_array, full_path, `n% j% \6 O' d! {; z! A: l* u
  ; Take the first element from the array6 V4 F3 Q2 ?+ M* N( a. f
  full_path = %word_array1%% W/ |' R% ~, O, u! t  Y
  ; strip to bare address" E, t- T+ i+ i5 W7 ~6 \. ?; y
  full_path := RegExReplace(full_path, “地址: “, “”)
! r* r7 _7 l, t" Q! F  ; Just in case – remove all carriage returns (`r)
  }) \2 \+ S' h- p4 J) r: S9 R1 w7 J  StringReplace, full_path, full_path, `r, , all  z8 s/ a7 r+ A! R- e8 Q9 Y. S, t
  IfInString full_path, \  N6 y' |8 f# M; n# a8 X5 Q
  {
3 y" M, M! |6 J* o) z  Run, cmd /K cd /D “%full_path%”
3 s& d. e- w, A# K  v  }3 P. J* Y5 F& c" x) k. y. A0 j
  else
% k  f8 \# O! z1 \4 G% G% |# ^) Q  {
: B" C6 f. u4 o$ S7 t. H* S- g  Run, cmd /K cd /D “C:\ ”1 V" ~3 ?7 x1 o) A  J% |
  }7 `) A) X: d& |
  }( a' w( H, G( s: }
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
2 ~% M8 b- s- _) X2 v0 a  这段小代码肯能有两个你需要修改的地方6 s$ B. Z" D4 r1 I
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键' P) d& ^) k( ^  s3 q1 \
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
! S4 n( O4 \- U# I  V
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-3-4 16:02 , Processed in 0.123860 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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