电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
# a4 C8 V6 _& }9 K+ K. K4 L  p! F  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。4 b6 A  \9 t0 t: u9 V
  方式一:
) W& P8 P: z2 G0 f  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
  M3 Y/ q  \) ]( Q& a& ~9 w& w  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和" p2 l- ?  f7 I- e6 |" \
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。% K+ e% [9 B9 y" N, w
  方式二:
6 I1 T6 X7 n6 G% h# v( i  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:/ \8 T) E1 T! i* x
  SetTitleMatchMode RegEx; D. k6 a6 l9 X; E5 R- n4 l& q
  return
, f  t% t, a9 N2 U, j  ; Stuff to do when Windows Explorer is open
: I5 H9 y6 |. s7 P  ;
4 P; D  ]' E, h, p( S. h8 e  #IfWinActive ahk_class ExploreWClass|CabinetWClass& L8 ~9 u9 S9 w2 O
  ; open ‘cmd’ in the current directory) c  B8 @9 ]* H" m! P8 M7 o1 t3 N
  ;* L8 d5 _: ~7 ?' `0 L6 F$ W
  #c::$ G' h' n7 q; f4 s2 L+ ^
  OpenCmdInCurrent()) Y- B. B. Z. h3 i# i" r
  return! d3 P$ L# q! [* S
  #IfWinActive' W6 d5 |7 [' F/ \8 Q
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
3 @+ ^4 D# c0 [  ; Note: expecting to be run when the active window is Explorer.* u0 z8 ^$ M/ q! K# |
  ;
# z; X* P% S6 E, J/ C" A  OpenCmdInCurrent()2 ~7 L! l5 y3 N4 W8 R
  {
, `# I+ S8 [: R; F! N' O" X) T  ; This is required to get the full path of the file from the address bar: Y  X7 M2 s) ^  q# O2 ^/ v/ {
  WinGetText, full_path, A
$ k0 g! F( z, e7 @  ; Split on newline (`n)8 e5 V! ?- O7 J$ L2 w; F$ {9 p
  StringSplit, word_array, full_path, `n+ d  w# d: W/ ~1 F, W3 R% m
  ; Take the first element from the array
0 C- ?( r& m& O7 X) n. p  full_path = %word_array1%
. h: |3 t- ]" U# v: @  ; strip to bare address
0 [. \8 o& |* J( e* C5 C  full_path := RegExReplace(full_path, “地址: “, “”)8 c5 ]' f1 _7 `
  ; Just in case – remove all carriage returns (`r)
% F; ^- E# |! s& W  StringReplace, full_path, full_path, `r, , all
; W% @3 J, b( y  IfInString full_path, \) s" i, z6 b9 P4 b
  {3 J' F& S$ P3 Z9 s" M
  Run, cmd /K cd /D “%full_path%”1 {* J, {" q! j* f. z0 c
  }0 r) d+ M6 x0 ]( m+ X! b7 v
  else# {/ ?' R, \) l3 r% K
  {1 s$ k  O+ a4 n) B1 n. H
  Run, cmd /K cd /D “C:\ ”
. K5 x, V$ y( ?# Z  }7 T0 l9 }; x7 v1 ?+ u
  }
6 J; E" m7 B) _6 L0 x  a: y3 d  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
8 C; b1 t* D' i  这段小代码肯能有两个你需要修改的地方$ q# ?$ Y. g6 R! }  h9 g: b$ n1 S& ?
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
' q, G+ f1 O: `# F! k7 w5 |  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
2 O& B+ M0 ~0 {7 p% A9 s& q
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-4-12 19:47 , Processed in 0.057112 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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