电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
0 E1 Z- }; G7 Q8 f: q/ c  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
5 `# L! p6 K" J0 F! w  方式一:
- Z1 Z$ n, d4 k7 M- u/ T! ]3 m  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,! C1 w  p& G4 |9 g+ ^" m) r
  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
7 [- A- P3 B! ?) A* K  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。3 H: X# _! t9 s8 J
  方式二:$ S, F( L1 I- n
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
; o$ @/ K0 J# b9 c. B  SetTitleMatchMode RegEx
( {& l  h' g! H6 k/ u  return1 e0 H' ~( y# e
  ; Stuff to do when Windows Explorer is open* W7 R# t- b& }& i6 N& g( g
  ;
3 J8 z! ]" h2 O8 `& v  g/ u  #IfWinActive ahk_class ExploreWClass|CabinetWClass$ C8 {3 ~: E' u6 j) @9 U
  ; open ‘cmd’ in the current directory
" }" s9 R& p6 S) r) ]' [. C; J  ;! A, f) R' s3 g# L, Q* @
  #c::  e) `0 q0 |; V* x1 m
  OpenCmdInCurrent(); U, q0 t7 M; w1 ]) O& m$ W
  return# t# i6 o2 {8 N8 ~
  #IfWinActive6 f8 O8 h4 W$ O- S8 O# L
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
3 J# O7 V9 ?1 _4 C; t; I  ; Note: expecting to be run when the active window is Explorer.3 ?5 K+ }+ W1 F9 z+ {9 z
  ;& r) x3 W; k) x3 g  ?
  OpenCmdInCurrent()7 h$ u$ A. N+ A" K1 h$ v# I2 X
  {
5 x9 K  Z- I9 B2 O) j2 u/ `  ; This is required to get the full path of the file from the address bar
' y4 A# i) k0 h9 J& X! T  WinGetText, full_path, A
& `& R& e3 P# f' T! ~% s( k  ; Split on newline (`n)0 z1 s; K& G( L6 I5 P; D
  StringSplit, word_array, full_path, `n% O+ u- O: i! \. S% _( m# N
  ; Take the first element from the array
- G* n( n+ b! M! u# g$ Q  full_path = %word_array1%
) [* I5 q/ O* d# E" C  ; strip to bare address* O( P0 h8 x8 ^
  full_path := RegExReplace(full_path, “地址: “, “”)
1 c7 y% q$ }  P0 g4 f9 v( X# H  ; Just in case – remove all carriage returns (`r)
2 k$ {" w3 ^+ |7 v" i  V+ x  StringReplace, full_path, full_path, `r, , all9 s6 x$ B: X8 m( s
  IfInString full_path, \: N, ~, {8 }$ ]& Q: n, Z" [- ]$ O
  {
5 f  ]4 P, V) c6 t: n5 Y. z' A  Run, cmd /K cd /D “%full_path%”( a  P% @0 O' k6 j7 w
  }+ m0 p4 V% R* I% t! ~6 G  y
  else
+ x/ X9 v0 Y3 ?% l$ {* ?: S  {' z. k$ `: r  o4 U$ F. y: ^* A
  Run, cmd /K cd /D “C:\ ”
! F' a! e9 P, ^: P5 J  }8 N9 b4 Y  p# U* K, X( Z3 a
  }
/ N5 Q9 o8 l: q" V. |  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。! ~2 g0 k, l0 B
  这段小代码肯能有两个你需要修改的地方& D8 j! b* D; Q: M* ]( Y$ N
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键/ n8 L, w  a4 s$ g
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
: o# _, u6 K9 |& @$ G. F- |6 e% k
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-3-4 18:07 , Processed in 0.076798 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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