电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。/ Z* c! r( S) c+ c
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
' M" }9 Z) c0 C* P  方式一:
) K' d  _% H* z  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,5 Y) n$ f9 n4 W: g) E
  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和( t% ~4 p  l1 g: e  a  [
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。, S8 |$ q: Z. i. u0 M' U( C6 v
  方式二:
/ i. z5 Q+ J. p5 ?! ?1 _, A  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
' F! R6 [% l& _7 t, s  SetTitleMatchMode RegEx
, F- |% b) ^6 N# s' y6 ~5 }1 M  return: G! f! S, d9 A5 x2 j% @
  ; Stuff to do when Windows Explorer is open
0 W& C" Y1 ^! m  v  ;
$ h( R" N$ Y5 O2 S, n! m/ a  #IfWinActive ahk_class ExploreWClass|CabinetWClass
2 w0 [: m# T; c1 Z  ; open ‘cmd’ in the current directory2 v5 {) C  c, ^5 ^' P5 Q
  ;* e; A9 Y4 P  C7 Q: Y& Y
  #c::
7 ~8 m( ~, e( r  OpenCmdInCurrent(), Y. Y. X/ s* {4 H3 U# l
  return4 M. ?1 D! A3 H7 f! W. w
  #IfWinActive
- q, T1 Q+ K( n. k( M# h$ {  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
; ]" D  }, P4 O$ s" G5 b! k( |3 _  ; Note: expecting to be run when the active window is Explorer.7 S' _, |! f' d3 F# l5 P9 M+ `
  ;
# v3 t3 l- ~& m7 g' V# J7 ~1 J9 C  OpenCmdInCurrent()
! P- M( N2 t" ?* H0 E  {* }% i/ ~' I" F) b
  ; This is required to get the full path of the file from the address bar" j$ M7 r2 {0 q9 }' C, o
  WinGetText, full_path, A$ T0 t( b/ |2 `7 d
  ; Split on newline (`n)
9 G; {2 W2 A5 M6 e8 d  StringSplit, word_array, full_path, `n
* Q& ^: m3 c& [0 Y8 z, z  ; Take the first element from the array
. t, S2 u: B- U7 W+ h1 f  full_path = %word_array1%
8 H) |) I" v. _8 r4 ?7 P5 \  ; strip to bare address
% U# x8 ?8 V7 @5 N  full_path := RegExReplace(full_path, “地址: “, “”)
9 P8 i, u; ]. W: C4 {( D  ; Just in case – remove all carriage returns (`r)
! |3 E, }0 x) X% s# n) Q  StringReplace, full_path, full_path, `r, , all
! r0 u1 @# W# ?$ f  IfInString full_path, \
* j7 w" G  V8 |- p; g7 Z  {
; g  h1 R# q( T2 w; H  Run, cmd /K cd /D “%full_path%”
7 T  a6 i$ p9 d  }
* X5 Z3 [% Q9 F4 h2 U& w  else% y" G* [& j* Y( v* g$ w4 E) O
  {
7 C$ y2 u& o. |  Run, cmd /K cd /D “C:\ ”% r; N3 ^+ A9 u8 P0 S
  }0 ^% x7 l5 ]; j# ]) Y
  }( y5 A2 ?5 A) N5 o& ?
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
  y" ?1 b0 D' U9 U5 ^  这段小代码肯能有两个你需要修改的地方, d# D4 J' s7 [8 B
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
# o( l. v. l9 U4 V& {; e  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
# G7 B5 m7 V: g! W6 ^8 M
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-5-7 17:01 , Processed in 0.132758 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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