电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
8 J7 ~) T. L" F6 Y3 X  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。5 ]2 o5 T* k8 G& c- g
  方式一:
& P; R5 M" J, @4 w) e  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
0 i3 m1 p$ y  H& t7 Z1 |: \9 O  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
  j* W) o" |, L  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。/ y2 I1 \( Z! ^
  方式二:! H1 v6 H& G6 K! @1 O
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:3 t4 q3 D; K) \! N# F% ]4 g
  SetTitleMatchMode RegEx/ `; Y2 ?5 `* C3 Z- g
  return1 g) D; P% y: v  K% s# L1 {% e+ ]- O# q8 y
  ; Stuff to do when Windows Explorer is open
: _/ p6 c4 n( `5 G, d" e  ;
6 _1 k* N! j. h  #IfWinActive ahk_class ExploreWClass|CabinetWClass2 Q, a8 s, i0 l# z# U" Z7 t; j( N
  ; open ‘cmd’ in the current directory* p6 u. B, h0 h0 @/ |0 V" W* |& f/ c
  ;
6 w* V' e# ^( y; ]% k5 G  #c::1 E# m# a$ Q2 I4 s* L
  OpenCmdInCurrent()
5 p! B" w+ u0 q4 R+ l7 |0 j  return
; {$ b+ t7 W# J& w6 n5 q2 V  #IfWinActive7 K2 c8 ~$ T2 O2 ^2 e
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
' w$ k8 ~- R9 `5 T0 P  I  ; Note: expecting to be run when the active window is Explorer.
1 y, r) W7 n0 X% U2 B. P0 B* A  ;
% v: s; T/ f7 z% K" v7 s  OpenCmdInCurrent()
9 b0 }4 ]6 ?- Z) E+ @# j4 i  {2 L" U/ G2 t  B& V0 P& _
  ; This is required to get the full path of the file from the address bar
* k, @+ `) e( c5 f9 l  WinGetText, full_path, A: ]" {- H2 x" v
  ; Split on newline (`n)" p1 Y. g5 x8 ?/ y/ u
  StringSplit, word_array, full_path, `n4 `5 w) H0 a6 F9 q2 {) z
  ; Take the first element from the array, ^; T/ M/ ]" c+ d6 \8 y7 Q
  full_path = %word_array1%
7 S7 ?! ]: i0 ~( G) I. m  ; strip to bare address
) K+ X/ x, Z* A3 @6 l9 {% u! `  full_path := RegExReplace(full_path, “地址: “, “”)
$ \3 Z) p+ ?2 g  ; Just in case – remove all carriage returns (`r)7 E2 v# w- t) l* e4 t3 V
  StringReplace, full_path, full_path, `r, , all) C& t4 Q7 w7 b0 K0 u: O
  IfInString full_path, \0 k& J9 z% h! k! R$ \5 b1 |& F
  {7 E5 |$ _" ~% G# H! V9 a2 h( |5 M
  Run, cmd /K cd /D “%full_path%”: j: w0 l# C! `7 F* ]: z7 m4 s# O$ c; e
  }6 m7 T- C" Z& S5 u9 b4 M
  else6 K, Z- l% ~+ \% c+ |" j
  {
' }/ S6 X% X. {& q5 s  Run, cmd /K cd /D “C:\ ”2 W+ o9 `" y1 I) Q
  }+ [2 l+ w7 ]9 y) _9 C- n) k% H
  }
: c2 h' n0 m3 T2 j: q6 N  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
7 _5 p  ]# y1 C( [; }: c  这段小代码肯能有两个你需要修改的地方3 g& B3 i  x4 i6 B* t+ A, U. i
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键  x9 _5 _4 A- |: Z0 f
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “, y0 L) p6 m: H7 @2 A8 E+ z1 y
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2025-7-4 11:05 , Processed in 0.117004 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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