电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。9 l2 u+ N- z0 r5 e3 y3 `
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。% \! f6 H& ^$ q! p. Q7 T9 j+ D
  方式一:
  a3 i" h% c+ g$ e. V# p5 o  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
1 \/ p! U, @1 s- v$ A3 Y' n  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和5 y9 ^6 O  `8 j9 T/ L* x$ i
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
9 P% P; i6 K$ ~' l( v/ o# f( C  方式二:+ y4 Y4 |! Y* V4 k4 e4 \7 y
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
2 T  C% i  D' x0 E  SetTitleMatchMode RegEx  d8 ^0 Z0 t7 P. l; g8 C
  return$ s  B$ P. X& }+ t6 g: o; V
  ; Stuff to do when Windows Explorer is open: L  R3 E$ b, X5 U
  ;. `3 \& X$ _: N" F
  #IfWinActive ahk_class ExploreWClass|CabinetWClass
7 X$ H6 ]  V# A9 Y/ G  ; open ‘cmd’ in the current directory
$ N: h1 ]1 t% M3 M$ @# W  ;
+ p) P: {2 J$ I0 B2 t! q2 e7 u  #c::# N: F+ R; S6 r  x5 }$ |. }
  OpenCmdInCurrent()) k! W' D, J/ u# h
  return
- C, [1 B1 b$ P0 H) {9 p: }# d, _  #IfWinActive
$ L2 r7 |1 l; I4 `. o* O  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
2 q2 K5 R0 H5 S; l! s  E! }; ~% h" ?  ; Note: expecting to be run when the active window is Explorer.3 p' J* @# E# N  I
  ;* M+ u# f) Z% {8 }9 d' u0 e
  OpenCmdInCurrent()
0 ^( f9 R; [8 D' r+ f% q/ ~  {' ?. r5 K! ~# Y$ B+ m7 M8 V
  ; This is required to get the full path of the file from the address bar( A0 u1 E1 r2 ]) i
  WinGetText, full_path, A
2 q& l( h: r% h. b" y$ g  ; Split on newline (`n)" D3 ~: Z: d  t) `: o; w
  StringSplit, word_array, full_path, `n
/ [+ ~* e* r9 g3 r; U( x  ; Take the first element from the array9 o+ {9 M' [' i1 {6 }
  full_path = %word_array1%
' n: P% Y% k- L* t- g: p  ; strip to bare address
. t2 X7 [; }! X9 l1 X7 P5 w  H  full_path := RegExReplace(full_path, “地址: “, “”)4 ~/ A  p" c7 P
  ; Just in case – remove all carriage returns (`r)8 y' D: P8 n  o1 U. n8 P- ]
  StringReplace, full_path, full_path, `r, , all
2 Y, q& @7 H, W- u  t6 |0 V# k  IfInString full_path, \3 G! z+ X9 G" t' ?
  {
- y- r- J; G8 G2 D& l$ E, h  Run, cmd /K cd /D “%full_path%”7 R# p! T5 D+ S3 h# V
  }
4 H5 B( r6 b' B; P: D0 f0 Z  else
6 {' {1 s, \1 V+ N9 f# ~  {9 X' t- T% p: b2 c* D5 t7 @* I
  Run, cmd /K cd /D “C:\ ”+ S; f3 u/ }6 [& e2 @* b
  }
4 `5 O6 n3 V! h' F& p4 S9 V6 P  }
% a' ~# o2 T" f. B) |  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。( s+ M! r$ l/ i# Z9 o. Z
  这段小代码肯能有两个你需要修改的地方
1 ?( N6 u; V5 E8 V' {3 V  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键1 \+ T* I3 |" j
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
# |: s  f; a( W
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-4-10 18:44 , Processed in 0.080969 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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