电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。- X, @8 C/ `; Q. J0 w* |2 c
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。/ ]+ T+ R5 p$ G" x* j& o9 f
  方式一:/ @, c' Y# E: J! P( F
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,8 p+ g) o; N! N1 Z* t: I
  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
) f' Z( N3 q! R0 ]) T  I  e  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
, c0 L0 K/ P* T( s* e& w: C  方式二:3 ^; ^' H) K5 F$ p. r
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
! f6 \2 e0 r) e( ?! E8 Z  SetTitleMatchMode RegEx" }- P: C/ P% V( p6 Q  o
  return# T# d: L! |  V
  ; Stuff to do when Windows Explorer is open4 s0 y4 x" o( s  h$ c. N: q2 D
  ;
. G0 g( p- N9 l  #IfWinActive ahk_class ExploreWClass|CabinetWClass! A7 C/ [% ]  y8 ^
  ; open ‘cmd’ in the current directory
9 V$ f" ~# B5 Q  @3 F7 i  ;
6 ?, D4 ^7 u+ l* R  #c::, y1 ~* V  B+ [: k' g
  OpenCmdInCurrent()8 J+ _" k- i. Z0 |5 K
  return
, M3 L) S8 Q6 d, _' t8 n% j  #IfWinActive
' b$ }, }# ]! d7 I9 A. ?. {* I  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
. n& g- W4 m  J  ; Note: expecting to be run when the active window is Explorer.# ^0 a! Q1 G% e7 F
  ;
, i& R% u# E& u8 w: O  h& |: Y  OpenCmdInCurrent()0 M( G/ O# ]& E3 y3 |
  {
3 }% E! e; G  Z/ j  ; This is required to get the full path of the file from the address bar
, M) ?- i+ r6 v4 }4 i+ ~6 V4 P  WinGetText, full_path, A
, ?" c# L3 X" i& z  ~  ; Split on newline (`n)
" [' d* s& w3 L5 O* K6 m2 M  StringSplit, word_array, full_path, `n
- N; \$ X! N9 w7 q3 X: ~  ; Take the first element from the array# L. s5 L7 R7 i9 ]
  full_path = %word_array1%
: L" I/ m6 V/ J4 b$ D) r0 {9 [( n) h* ~  ; strip to bare address& {0 V) a6 H! v; A) D$ \
  full_path := RegExReplace(full_path, “地址: “, “”)
0 ?% f- `/ n' w) ^0 q  ; Just in case – remove all carriage returns (`r)
2 U9 _* k$ j/ _+ l  StringReplace, full_path, full_path, `r, , all6 i) _" q2 f' U) ?2 r
  IfInString full_path, \
! _( N- J# {, n% t$ G  {  e$ s- U4 l' _0 n" J9 f
  Run, cmd /K cd /D “%full_path%”5 K' y2 A& [; @0 E3 v; Y
  }8 g& I6 K+ f! N9 w8 N
  else1 N2 H( s4 K# Z3 Z7 K
  {; p  B0 Q- e% _& ^# ?, [
  Run, cmd /K cd /D “C:\ ”: A2 ~# P5 L. Z$ x5 {
  }& G0 v1 ~. O4 t  u( [
  }, g& ?; O8 G3 ]; H$ b2 e
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。! T8 j9 m% v" C; P! y/ \
  这段小代码肯能有两个你需要修改的地方
9 [2 `; g2 X8 M) g0 e6 m% J  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
$ [- [' [1 b2 o/ t1 Z3 J  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
3 t+ R+ }0 E: c
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-5-27 04:31 , Processed in 0.082719 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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