电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
4 }; C, U# V1 @# s  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。6 ]; R) O& Z) Y) l
  方式一:* G2 s- Y9 ^: \- H* c3 J
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
* i2 D' j" F! T6 ^  a  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
: [3 s% x) l3 T9 f9 C8 v  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
' W/ @9 @; Z8 I  _' j  方式二:
2 ^" P7 G5 e& w7 A4 K, J$ ~  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:4 v( a+ M9 ~1 r) [% B* P5 C" }
  SetTitleMatchMode RegEx
. \4 r7 S/ A: l4 P( d3 f! x3 Y  return) L' [6 r7 i0 Q, A& z, M( s- p6 ^, d
  ; Stuff to do when Windows Explorer is open' Z7 K7 m( i( k/ r& v- O, S
  ;0 E8 N; ^- U; ?' e/ @
  #IfWinActive ahk_class ExploreWClass|CabinetWClass
1 a4 [- ^% a- }' B$ ?  ; open ‘cmd’ in the current directory3 Q% w- E% v& Y0 K3 Q( @1 V3 T
  ;+ u6 Q4 n, K* o
  #c::: z7 M- t' A( o$ g+ K
  OpenCmdInCurrent()+ p2 A" f& k, S* a4 t- b1 X3 K: o
  return
5 m8 J' b, n( o2 l9 [  #IfWinActive' _, A$ s; ], x5 C5 {4 q0 c. j
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.4 N5 w1 n7 ?8 \( t6 F; ?
  ; Note: expecting to be run when the active window is Explorer.
' v# W5 b  D& r0 B2 O5 {9 D  ;
1 E# _' h! G7 \* O8 N! c9 r  OpenCmdInCurrent()
+ i+ k9 I9 k6 l9 i; O: s% x  {. H% v7 o" q$ ~# H- ~$ B
  ; This is required to get the full path of the file from the address bar, f# P; c& c& F: p. q1 _  A4 ?  c
  WinGetText, full_path, A6 F7 N: Y. q2 j, W3 y0 \, C/ e
  ; Split on newline (`n)
. `. G" \+ n5 U  StringSplit, word_array, full_path, `n  z0 e! |  S" \  d% L" P0 W
  ; Take the first element from the array
/ J% \5 t1 N( `1 c  Q" P3 }+ R$ t2 _, @  full_path = %word_array1%
$ J# D2 R3 E( q4 v0 v, i  ; strip to bare address
8 p4 |! S, V9 w! d5 g' k  full_path := RegExReplace(full_path, “地址: “, “”)
  V: @. E  a% `" N+ v  ; Just in case – remove all carriage returns (`r)8 x2 o0 B' }3 b0 h) e+ K% m
  StringReplace, full_path, full_path, `r, , all
7 f: F. W7 J: D) D9 Z+ t2 v  IfInString full_path, \( S# d) X3 g6 O) |9 w0 Q5 W
  {; V0 R# N0 |1 I0 P
  Run, cmd /K cd /D “%full_path%”& c$ O) v& x8 d# C' g6 n/ x
  }: W% a8 Y, x# n
  else  S  A* i+ n# k/ `# O
  {! P- h/ F/ `9 P; ]  g2 y0 t( u
  Run, cmd /K cd /D “C:\ ”
$ |+ \. G9 S$ z: ~( |  }! X! D9 J' V% i3 S) \3 e
  }& E" v7 p$ N1 L1 o* A) u7 T4 ?( p
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。5 U, z; d  }  b4 F$ l
  这段小代码肯能有两个你需要修改的地方! W: D# z' ]2 Y
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键  Y& ~: Y& ?5 H; L
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “& U4 H8 m. o& g6 k7 B9 n1 K9 L
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2025-10-25 04:50 , Processed in 0.064333 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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