电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。/ E  |3 i0 m; L
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。# {" x. {, l0 i9 _, v( T$ _- f) ?+ K
  方式一:
; C0 H$ d$ c1 i  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
) \; p, V7 G8 b: s8 f1 a) Y  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和3 v8 E- S2 d" e1 [$ Y" L
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。0 j. Y2 f9 A+ E( X9 P
  方式二:
- d$ t7 _( s" B$ C$ Q6 N3 J8 d1 ]  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
5 ]% Z6 s; U! J$ p- ^  SetTitleMatchMode RegEx2 [6 v2 c3 Y1 N6 w
  return
5 R% k# V' q. k" |  N  ; Stuff to do when Windows Explorer is open1 \* _/ \# e% S, `9 o5 z* b
  ;, z+ y, S. P( R. g
  #IfWinActive ahk_class ExploreWClass|CabinetWClass5 L" f# S  {" _* c3 w% a. \; D6 B
  ; open ‘cmd’ in the current directory
- a( A4 }9 s, D+ `' R% g' U9 n  _  ;9 o: W3 }! h6 P$ a
  #c::
; c3 Z2 O  d& o5 ]. f  OpenCmdInCurrent()9 w$ S& ^# }$ |8 ]- ]
  return
- h7 C# ?; C: l9 i/ N6 D3 }  #IfWinActive
8 ^9 _' d* s5 v" [  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
0 O; _1 f" x: A5 ^5 k  ; Note: expecting to be run when the active window is Explorer.1 P/ e# E0 y& w, ?3 |
  ;
. q( S$ j* x' J* ]  OpenCmdInCurrent()
" J, t9 O+ J- w% [4 Q  {2 t; v2 n& x' c4 \( A
  ; This is required to get the full path of the file from the address bar
4 T* Y2 k$ G0 g( o4 S( y  WinGetText, full_path, A1 `( Y4 d$ q( M3 }) v; w2 K
  ; Split on newline (`n)
- N& c, q1 S1 ]+ D- p  StringSplit, word_array, full_path, `n" Y- u. D$ x8 U
  ; Take the first element from the array+ h0 M! r' T& \, P" ?
  full_path = %word_array1%
6 b& v' P4 F6 a7 ~  r0 z+ Z$ O* [% y  ; strip to bare address
( O+ x1 |4 |) F+ B% e: V  full_path := RegExReplace(full_path, “地址: “, “”)6 k6 M) q1 j! b4 v0 O4 a
  ; Just in case – remove all carriage returns (`r)
- a( I0 ?$ W5 p  StringReplace, full_path, full_path, `r, , all
" d& [9 u: e8 |  C8 e$ T  IfInString full_path, \3 Z* h/ ]; a( W% T3 }
  {0 N" _4 D' C/ I
  Run, cmd /K cd /D “%full_path%”5 J$ `) l/ z( m+ v8 k
  }
# l# i* W6 c2 k5 t* A8 j( p  else
. b& J- E& X" P" g* A' j5 L  {# K1 Y! N/ B0 c/ Y
  Run, cmd /K cd /D “C:\ ”5 c" P- T  k/ d6 K, d+ t
  }
1 ?( f1 W  y; F4 o" _  }% s2 z$ g* b6 t& g, m9 s0 e
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
2 D& F# H% X( v  这段小代码肯能有两个你需要修改的地方3 F4 Z" d; X( _& U3 u+ \5 s, b
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
5 A3 B- s4 J& g8 M4 r! _8 b  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “9 i# W$ s4 m6 ^
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-9-5 01:17 , Processed in 0.086711 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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