电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
7 e. z8 g! x& h* Y! n' y5 s  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
+ J! K; V9 w% a( _( [+ }) e  方式一:$ h1 E; K1 `4 r/ e. Q
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,  M% J! h3 j8 v1 }
  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
) u5 a3 D7 f; c! K8 I5 I  \4 r  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
. n% S; A2 Y( a4 x' {$ [* \( K  方式二:1 \& l, r' M' S0 @
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
' g/ r/ s5 f. _0 @! H" P3 N3 g8 b  SetTitleMatchMode RegEx
( z. I% h' L, ~: f  return" z% a3 B9 ?5 x% ~
  ; Stuff to do when Windows Explorer is open
% T4 z, A2 k2 s. g" f% b7 q  ;5 G3 |6 F1 j6 a; C8 d
  #IfWinActive ahk_class ExploreWClass|CabinetWClass
9 o4 \; }4 U5 v4 Q4 A/ P! s" d8 K  ; open ‘cmd’ in the current directory4 {: l2 w% ~+ q& g: E# [
  ;
) \. I0 B% X3 O0 ]  #c::5 L  t* M8 Q- c  \
  OpenCmdInCurrent()
! h. n4 K9 V4 d+ f2 m% \7 n  return
. W5 E: F3 x. y# I  #IfWinActive
  N$ b, @2 g1 R" A+ ~  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
9 v; h: i, ~7 U& S  |8 p  ; Note: expecting to be run when the active window is Explorer.
. }! b3 P* n# V  D, L4 n1 h- H1 i  ;
& Q- l7 [7 B2 g% Z. ]  OpenCmdInCurrent()! O+ B3 n$ g0 J) P8 Q# o+ b( T
  {
0 j$ p$ A$ {( l) _" A6 @  ; This is required to get the full path of the file from the address bar
2 W- c. Q9 x  c3 l( O  A  WinGetText, full_path, A
+ N9 _, ]/ m: [( H  ; Split on newline (`n)  P' v8 F: u8 z; [9 l
  StringSplit, word_array, full_path, `n. @) \6 N- i9 y/ d2 T9 V8 W7 }
  ; Take the first element from the array
- a# o" k1 l, n8 G- F2 r$ z  full_path = %word_array1%7 |+ T  g0 M2 @' R8 Q9 R
  ; strip to bare address6 k! R2 n/ W/ S) M7 F: Z  O
  full_path := RegExReplace(full_path, “地址: “, “”)
) q! w( o2 ?3 E  ; Just in case – remove all carriage returns (`r)
2 N3 D5 `! }: \  StringReplace, full_path, full_path, `r, , all
1 L6 a" _; d, M( Z2 m  IfInString full_path, \# x$ `# Z" c6 ]
  {
( M# f" K0 u3 I, s/ s+ T# n  Run, cmd /K cd /D “%full_path%”, Z, j* {* l  p5 B: b& X
  }: d* \" q; e# A: f( d, G+ L
  else- L1 X0 w" |1 l- _- a/ r
  {
0 o: I" m  ~- e- U' u  Run, cmd /K cd /D “C:\ ”
2 u$ D; ^7 B: o1 O: Z2 K6 E8 W+ q  }
# a" N  M/ n6 M8 ]% t; |. \9 q  }
* O; d7 h9 q2 Q6 Y  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。2 l' h$ `6 i1 I# q: r
  这段小代码肯能有两个你需要修改的地方2 ]7 q; Y1 v+ h6 f
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
, r6 Y* w5 s5 y4 _" T% s1 V  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “1 s( _6 W- [: i9 C0 j
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-4-23 14:37 , Processed in 0.089537 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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