电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
& G3 ~3 O# W* t" Y) c7 b$ y, m3 |  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
% W" L% I4 m( i& n! D  方式一:7 @' n) e. K! T) g9 U* b( R5 T$ W
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
7 V7 L8 }; F5 V  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和4 U+ }4 h/ _" U  x! C) ~# ^
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。0 P: O% m; G. k1 n( _
  方式二:% G$ j* _# D) Y5 Z2 H& K3 J
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:% D$ h: J: }' g/ t, s+ b9 d3 }3 E
  SetTitleMatchMode RegEx
7 \% A6 U4 J! p" B9 B( O, |) T5 |# k  return
* K7 b  `4 W& g+ o( k* V  ; Stuff to do when Windows Explorer is open  c0 E' `5 ~% f; Q! d+ _6 e
  ;
! k# B4 q& o8 D' }5 d5 f' y  G  #IfWinActive ahk_class ExploreWClass|CabinetWClass  i7 [. r# T! ?
  ; open ‘cmd’ in the current directory2 p+ e" |# o4 e
  ;' n  a' p& H8 D( N; b4 \
  #c::
# @  K4 k/ n6 _9 i) b7 o& r  OpenCmdInCurrent()) [, F4 H' v' m3 h4 y
  return" c$ E0 }) w4 F3 h8 X1 s6 L
  #IfWinActive: B2 v* f+ B% i0 `+ I- f
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.1 l5 ~$ T4 G: O2 w
  ; Note: expecting to be run when the active window is Explorer.
# c. G! j8 ]. R1 C4 V  Y  ;
! [5 z- g* h( r  j' Q" @7 F- X4 q  OpenCmdInCurrent()
% u! s9 r' b5 m$ q  I' K, W  {& m3 }' y$ Z( z/ V6 Q! r8 r
  ; This is required to get the full path of the file from the address bar+ g( O- v$ F$ q! w. s1 N3 v' z: n4 g
  WinGetText, full_path, A; q; g8 Y; Z& `4 u2 V
  ; Split on newline (`n)5 G; e7 f- O# `
  StringSplit, word_array, full_path, `n" I+ p, U  \, o, `
  ; Take the first element from the array  R) Q4 n0 J2 P' o( c) n* I; q
  full_path = %word_array1%
" G3 g, m# E9 d# j& t0 i1 ^  ; strip to bare address
  g. W9 ~, }5 u6 o  B  full_path := RegExReplace(full_path, “地址: “, “”)- ^0 d  ~  Q8 a3 }
  ; Just in case – remove all carriage returns (`r)- E) Q" q* r) M' W$ n+ }
  StringReplace, full_path, full_path, `r, , all5 n; c% ]. W1 U# A- _
  IfInString full_path, \
3 \! F. A) V7 R8 C) W7 D  {
$ k) l6 n0 w% r; b  Run, cmd /K cd /D “%full_path%”
' @6 x: T- h9 I, |4 C, y  }: b0 B2 f+ @. d- s0 B$ @! D) s
  else
( v- U; r: }% z4 Y7 Q. `9 D  {
1 U* c6 A! Y9 T7 U4 j, n  Run, cmd /K cd /D “C:\ ”0 @. a3 t  N  c- l
  }& F" s) a9 ?) g& }
  }
; B0 w: `! Y$ {% O; X0 l: {  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。& N3 g4 n% `  [* X6 E3 g. H3 b7 {
  这段小代码肯能有两个你需要修改的地方8 K; U$ z2 C7 M# V
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键9 A+ t0 A  ]1 d7 a6 s3 y
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
7 S2 X- t: Q7 O3 w6 f/ d) P* q
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-1-11 09:01 , Processed in 0.056566 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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