电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
% q( z% i, ~9 a7 N. \; K( G. [1 `  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。+ G, ~2 q; e5 P5 k; D- b; K
  方式一:4 P) o2 V* U6 V% K% ^
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
) J) K8 `6 N% [: F/ o1 {, i  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
1 h* e5 _' c4 F+ ]  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。6 Q/ x# x% ^" f  C' Z- d
  方式二:
5 @5 e7 n# |: X0 t+ |- ]+ m6 K8 q  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:5 _1 ]0 j2 D9 u! |$ j8 l; s' S0 p
  SetTitleMatchMode RegEx% g8 T9 V! K/ A3 W  J9 H
  return' D! Q% a+ U  E! K. [+ p* g
  ; Stuff to do when Windows Explorer is open& i2 ?; b0 X1 t  ^
  ;- N$ q1 j; _8 g9 Y) o3 Z, n( T( j& Z
  #IfWinActive ahk_class ExploreWClass|CabinetWClass
8 q7 ]' ~9 ^. U: Z! G) I  ; open ‘cmd’ in the current directory
# }( g) E( K: ^  ;
( y% v. ~. D6 \  #c::0 }' I3 t  F1 u. T
  OpenCmdInCurrent()
& U$ N* T9 Q- a' Z  return
6 e9 C) F& U# b  #IfWinActive6 }9 @# i  N" |1 K/ i/ q- W( R
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
9 d7 ~/ B4 l+ |- ?+ e  X  ; Note: expecting to be run when the active window is Explorer.
- ~2 o# |9 }1 J+ l( b/ y+ d  ;
. J/ Q* S$ \, h" I  OpenCmdInCurrent()9 Q; ~4 O5 x  I. t, G
  {6 a5 Y; H: X" D! d+ s3 T
  ; This is required to get the full path of the file from the address bar
; n. n3 G( G* P# C0 m7 X& G  WinGetText, full_path, A
  u/ y0 [5 y4 T, M& ~9 V, K7 O# m  ; Split on newline (`n)
8 |' r; Y: o; w' t# z  StringSplit, word_array, full_path, `n/ i5 U7 a- n% F& |9 Y' d
  ; Take the first element from the array
8 u/ ^6 X5 ^0 K' y0 H" B1 X( ~  full_path = %word_array1%  c& s: A# [3 a, `' ~1 {
  ; strip to bare address9 J$ P2 D/ T, t1 S, e+ c
  full_path := RegExReplace(full_path, “地址: “, “”); C0 q, \6 @; n  I% d/ w+ D
  ; Just in case – remove all carriage returns (`r)# U8 w8 [# T) A, k
  StringReplace, full_path, full_path, `r, , all$ K, b- f3 r4 ~1 ^
  IfInString full_path, \
8 K$ ^, Y4 |1 i3 p  {
* e0 m, G. X& m9 q6 g  Run, cmd /K cd /D “%full_path%”
0 s" k3 C. C: F+ e# v, o  R, E  }
/ @# N8 T9 g2 ^  else, \1 C  {: `, J2 c$ ^$ }
  {; ?# p6 P: i" C: u% S' g; i' b. ~& W
  Run, cmd /K cd /D “C:\ ”3 k& ?& ?0 [2 s: G. I' c
  }, [6 _9 K6 Y/ ~* Q, Q  L
  }
( _8 M+ K5 c" }3 Y  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
$ x: \/ t& o" j8 s- I" l9 b  这段小代码肯能有两个你需要修改的地方; S4 |! l% K- g6 C
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键( Z/ Y2 L9 I8 t9 R7 E2 u' e/ c$ H
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
3 X# L& ^8 k$ G! V) U& I
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-4-11 06:47 , Processed in 0.055319 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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