电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
/ R/ O6 M& t$ |- x$ G+ J4 z7 z4 r$ ~  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。& H6 w1 t9 w; b9 p  S9 d! t
  方式一:
0 d5 [( n4 N  w& h) f% M  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,- n( O" b0 O2 Z, c1 W
  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和5 t7 \2 }7 {1 u( o
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
7 e- I: D4 M! L# v6 x  方式二:6 o2 l4 @# @/ Y: d
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:2 Y0 ~& @+ d$ H4 e/ L
  SetTitleMatchMode RegEx
9 f' @) X" P5 J  return
6 z$ R8 s7 ~. M" p* C7 S# _  ; Stuff to do when Windows Explorer is open
& `+ z6 `' h' n4 P& [8 V  ;, x8 Q% x9 l* j
  #IfWinActive ahk_class ExploreWClass|CabinetWClass
, _0 ]+ t: v1 X: a6 `1 ]  ; open ‘cmd’ in the current directory) L  A/ W& A+ T8 P9 ~& J
  ;# i: {' F6 J8 r" p+ W: F
  #c::3 z: I# s+ r% Z* Z1 r5 Q+ c
  OpenCmdInCurrent()  v3 x- e! W1 n3 P- L0 u% {% p5 m
  return% b/ q/ p% ^) D/ _" V. B( U+ @+ F6 g) i4 ^
  #IfWinActive
+ ]) V6 P8 y! J1 C2 \7 d7 O  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.7 Z6 @( C( Y& I: g$ s4 Z; ~$ ?1 Q
  ; Note: expecting to be run when the active window is Explorer.
6 c& {) h3 S6 U; K  ;, `4 U! y: t3 R6 q" v  e% A; O
  OpenCmdInCurrent()' R% |+ L+ f1 c& r0 D( K
  {- {! _/ X9 o: v, V( B: W) y6 N
  ; This is required to get the full path of the file from the address bar
9 n) [& d; H8 j% g  WinGetText, full_path, A( u8 N1 C2 S7 R9 w& J
  ; Split on newline (`n)
- W8 }4 X2 G+ A, _4 x+ m( p  StringSplit, word_array, full_path, `n/ ]' X. i  u9 a: m' _
  ; Take the first element from the array" c' R4 i9 P! `- @" ?
  full_path = %word_array1%
! m* r3 R3 V( E7 p. Z) g  ; strip to bare address
3 Z# V9 t2 M8 h/ M- S4 T  full_path := RegExReplace(full_path, “地址: “, “”)
( K: i1 U5 X9 t# B, l8 }  ; Just in case – remove all carriage returns (`r)
% q7 A1 ^8 O( y; X* _* f/ ?  StringReplace, full_path, full_path, `r, , all
( X! P. j- p7 ~+ z2 C/ C  Y  IfInString full_path, \+ e8 E! b" E( `; D9 E. l4 Q+ G% ]
  {& @8 F, H/ i4 q* v
  Run, cmd /K cd /D “%full_path%”
0 M) v8 {/ V& P9 a: F. ~+ h  }
+ A5 o" f/ w- C( Y1 t; N  else
1 r2 a0 g9 G' h* k8 ^0 B4 i' Y  {& G  h7 A* T( Q$ U' P- L
  Run, cmd /K cd /D “C:\ ”! H* r/ ]$ }% E7 x& T
  }9 v8 W5 x2 p9 n% s8 V, D
  }5 J) n) N9 Q1 Q* b$ t
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。: l- L6 ]' n: g$ f3 \. D
  这段小代码肯能有两个你需要修改的地方
, w! E9 |& l8 J% g  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
6 Y* T. h0 ?$ y3 k  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
) F9 g7 C6 M/ C
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-7-27 16:20 , Processed in 0.066672 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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