电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。3 D; z  \- K1 v4 o" u, r
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
* M! {4 `2 x( F# t  方式一:
+ M9 w9 l1 G. }0 A  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,1 [1 K3 a* U- }" P2 {+ F% L
  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和( u0 y$ }, Y& g: g
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。# e: ^' B1 t' T0 E) ^* v
  方式二:+ ^& o  W; |7 o+ t2 p
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:' N; T, c8 E, g; s: O: {  N
  SetTitleMatchMode RegEx
1 n9 w# B7 ]; r; N/ L5 \) c  return
( y" L, j% [3 Y+ o  ; Stuff to do when Windows Explorer is open/ C3 t3 e7 v3 j  V
  ;
& N+ ]! x0 W4 d; G9 x" g  #IfWinActive ahk_class ExploreWClass|CabinetWClass* D( t+ L' L8 l6 C
  ; open ‘cmd’ in the current directory) Q/ f) j9 e2 Z* U( O6 U; M2 V5 U
  ;* S, f" G1 |+ T/ ^
  #c::
6 M% o( y8 P5 ?% h! _  OpenCmdInCurrent()* ~9 q8 h4 j9 Z
  return
! E7 t0 O& s  a; f$ b  #IfWinActive
- m8 w0 n' n' ]. R  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
3 Z. h8 B4 z4 _( N* s! c4 a9 L* @3 x  ; Note: expecting to be run when the active window is Explorer.1 w- W8 Y& }" R+ j( |
  ;
& ^9 @0 R  A6 a: a- d" G* `3 X8 _  OpenCmdInCurrent()
+ S: U) a9 {8 w( f1 |  {
( @2 m1 U/ J3 n- W) H  ; This is required to get the full path of the file from the address bar
( T0 i: I" g! T  WinGetText, full_path, A
3 F" |( l# y: t  ; Split on newline (`n)
  f" ]$ W5 j# o4 d# m# M  StringSplit, word_array, full_path, `n
6 U2 n, H# F$ w! y$ Y$ z# h! q  ; Take the first element from the array
. _; F) J9 d1 w0 A4 Q4 s  full_path = %word_array1%
- E5 z( l; f6 ~2 ?3 j0 x( ^6 q  ; strip to bare address
5 P- @' ^6 O6 e9 m7 ^  full_path := RegExReplace(full_path, “地址: “, “”)
- ]# C5 f# L2 u, K5 A0 y  ; Just in case – remove all carriage returns (`r)
6 g, e% x3 ~/ C% q. `* a; S  StringReplace, full_path, full_path, `r, , all
2 ?, H4 u5 P  y) ^  IfInString full_path, \" ]' V' \: }2 [# U
  {( g6 N; R5 K* Z
  Run, cmd /K cd /D “%full_path%”% X, P* }( U, U7 C0 y8 {
  }2 W  H8 j$ r8 R7 {
  else
. J% _6 r' i8 C; g  @  {$ `; I) f+ |6 Z7 x. ^/ Z# o
  Run, cmd /K cd /D “C:\ ”7 i' B" D. D7 V: m+ t8 y6 M5 Z
  }* j5 b; y7 n! R% P
  }8 p, [" _% q+ n* J7 X' _
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。9 b" @) ^7 J# Y- r( P
  这段小代码肯能有两个你需要修改的地方  d$ u3 J0 E+ w+ E2 @. E$ C" F
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
7 f5 M/ H; _0 j; a; |! a' m- i  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
' V8 ~5 M9 h, Q. B$ A5 Z
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-3-11 21:34 , Processed in 0.054523 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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