电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。% c8 C  f; s0 h' f/ B0 C
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。% S% u; I1 Z  j( \8 a! }
  方式一:6 y7 s& R0 c0 ]8 p6 R5 B# [" \7 }
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
; h3 N, d. D7 z% v9 R  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和2 A( n  S: v% C( ?2 e
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。5 X0 O0 R# @6 F1 W0 B
  方式二:
7 ^/ i4 U+ n3 v6 D7 ?) t( @/ z  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
: r/ j* M  Y5 L/ s6 A' b  SetTitleMatchMode RegEx5 n+ V+ Z: }9 I. n
  return
' U. N* c6 J( s! h% [( J  ; Stuff to do when Windows Explorer is open
6 U8 m: n4 R5 E, ^  ;: D( b; _0 _7 k2 \$ z9 x
  #IfWinActive ahk_class ExploreWClass|CabinetWClass1 q! j0 I! I' j8 F
  ; open ‘cmd’ in the current directory6 [& h. A1 K/ Z5 h3 {. i
  ;
! o8 E4 G; X/ _: Y) i% V9 X3 i. i8 \  #c::% }! ?8 t1 z+ x0 E
  OpenCmdInCurrent()* A' R* I3 h; o8 Q* E9 F4 q; o
  return
8 B" R9 M9 }9 M7 ?, C, U  #IfWinActive4 a. @2 x  Q+ t9 ~4 w' Q: [7 \- Z
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
3 L" F* v/ i1 ?8 n  ; Note: expecting to be run when the active window is Explorer.) Q) O, W9 [1 v% a$ m
  ;
. O. Z6 |% S" D+ ^3 U  OpenCmdInCurrent()& A0 l) o; d; t2 l
  {5 `3 ^- W, r. J' l- \- U) w
  ; This is required to get the full path of the file from the address bar0 K1 q- @' [6 q1 R
  WinGetText, full_path, A
6 }0 U6 g4 x9 k) ]0 J  ; Split on newline (`n)
$ @; I' s& s1 n+ M8 B  StringSplit, word_array, full_path, `n
' O6 N* A" p5 Y- _, ?  ; Take the first element from the array) m' b0 Z2 P- g# E
  full_path = %word_array1%
3 C4 ~8 t/ D! ^' g% w1 ^  ; strip to bare address, t7 r% A+ J2 }* v1 q
  full_path := RegExReplace(full_path, “地址: “, “”)7 E1 J- ?# S5 c) h! l
  ; Just in case – remove all carriage returns (`r). o# ?. O' X& U9 `4 N" [7 j' Q2 T$ P
  StringReplace, full_path, full_path, `r, , all
- K+ E! y; [& A$ H6 C  o7 d' V  IfInString full_path, \- o) w; ?) Z1 r5 k* ]: |* R
  {
9 \) }( l0 b% t+ P; R  Run, cmd /K cd /D “%full_path%”5 X( W* n( {) F9 y# n* Q
  }) t' k' }1 ]; J: p
  else
: j6 }# F/ _4 n0 ~' _  {
0 i6 X0 `, i" H/ N; d4 C  Run, cmd /K cd /D “C:\ ”
% {7 a0 B% h( x. A2 f  }
5 z' o  G* k& n3 G  }8 g5 {" e# e5 Y/ x7 R/ u  q
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
" ~; J/ ~& [, L, V  这段小代码肯能有两个你需要修改的地方
4 ~! S4 j4 {  l: H9 Q/ d- Q  I0 E  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键( F& [$ n% F8 F" Q6 r7 I
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “% h( ?* S3 Z8 y6 I  y" A
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-7-14 17:16 , Processed in 0.081757 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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