电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。& q( h8 {( _4 l0 L' E  O. b5 V; q5 F
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
. t; q2 ^7 J# T: M3 E  方式一:
7 g" S: ^( N3 d  r5 n9 a7 u; P: T  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
/ I6 @: |# Z2 ~& S) W# A  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
0 K1 o5 w) Q0 P" \: b% M2 M+ Y  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
$ D9 E( [* A) G: t4 z  方式二:
4 N- s; u4 D/ Q: d* q9 X  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
, ~0 Q, ]$ H$ Y* |/ L0 H  SetTitleMatchMode RegEx5 \- {: C& P8 X+ `. b  {4 S
  return8 y7 j+ @, Q* E" e! v
  ; Stuff to do when Windows Explorer is open
4 P3 V  z) p$ U% S! m, w+ C" }  ;
. h6 G5 p9 b  J1 J  #IfWinActive ahk_class ExploreWClass|CabinetWClass; A% ?# r7 O) s
  ; open ‘cmd’ in the current directory  Q. L" n7 S- t- Q% r/ J
  ;
0 M- t3 A) `# b  P& p. n- p  #c::
4 Z4 Y! A& w" Q/ B9 S  k  OpenCmdInCurrent()0 ~( C9 b, R: B% s. }; \# }3 m  s
  return. j- n0 W: C! Y, @: y
  #IfWinActive8 S/ j2 ^( E' L8 K
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.3 f& T3 }$ X3 P, G9 Y6 _3 |
  ; Note: expecting to be run when the active window is Explorer.
, b% @; ~  Z" M  ;1 F/ f6 p) m& v; y9 i
  OpenCmdInCurrent()! v0 {, N5 ]* ^3 t7 z0 E; g: Q
  {5 k0 P! ^7 T) D
  ; This is required to get the full path of the file from the address bar  V: K" z4 g+ X
  WinGetText, full_path, A
& l' c5 N1 ^* P5 D  ; Split on newline (`n)
0 h- F# V$ s+ k! W$ K  StringSplit, word_array, full_path, `n: W7 Q3 ~/ o2 f% J# c1 |& P
  ; Take the first element from the array2 v) U( U  ^  I; D) f( c
  full_path = %word_array1%
; Z5 s* e$ ?1 H& r+ ^  ; strip to bare address( u  q& ^" v& R! A# Z. U6 F' f9 K
  full_path := RegExReplace(full_path, “地址: “, “”)9 D9 c/ n- {, T! F
  ; Just in case – remove all carriage returns (`r). L: e* n$ G* D
  StringReplace, full_path, full_path, `r, , all! O/ l" g' ^. ^: s
  IfInString full_path, \4 v3 \* |2 |0 |/ o" _
  {+ \, `* |( Y" d( l3 {  p* o# O9 {
  Run, cmd /K cd /D “%full_path%”6 n5 B. d7 r0 f. b* |0 u
  }& v9 O! f# I# Q- a( L
  else7 B$ C" F% d2 v( p
  {7 j# u/ c6 l! `: a! R
  Run, cmd /K cd /D “C:\ ”
; s+ ~' O' @; h' y0 Y/ |! S  }' s2 y, y8 K# L2 Y
  }
( t: Z% c" O- g. K  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
% l5 K0 H* a: |  这段小代码肯能有两个你需要修改的地方  Y& I0 y; [( d% @
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
6 e- t) I) B9 N# k/ J, f  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “/ K/ q# H1 [( I7 q0 J3 A
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-11-3 20:20 , Processed in 0.070565 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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