电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
& l: E' P( A2 p! N8 O  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
- W) ]9 H  e$ \) l7 \- |  方式一:5 z% B0 f' Z+ n. q) L9 I2 f! n/ Q
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表," I  t# c. d* @0 `
  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和+ X# G7 I2 f* q/ N
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。! f! ^% Y0 c2 a7 m
  方式二:# x0 ]9 j6 ?7 H
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
# x  F& i$ ?3 q: V$ J/ s+ j  SetTitleMatchMode RegEx
, @. P) R9 N, Q( p" R  return
6 n3 Q2 D4 X4 ^% P  ; Stuff to do when Windows Explorer is open
6 D! O. A: H% M3 M) E3 f! G) |  ;
% T4 `$ G* f3 C% w" l  #IfWinActive ahk_class ExploreWClass|CabinetWClass
% d6 K& m8 q5 L0 p) \  ; open ‘cmd’ in the current directory1 a9 R/ `- i* i
  ;. ^! _0 ~# Q0 \
  #c::1 |. c6 r% y8 ^+ r; [
  OpenCmdInCurrent(). T# v3 v! \/ D# [2 S/ \4 w' I- Y+ \
  return
. f& Z1 i! J$ T5 |" `  #IfWinActive
% p- C' U" [1 z0 F- k$ B8 C  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
4 H% M( k- Y/ m5 _1 c' M  ; Note: expecting to be run when the active window is Explorer.; }3 a; s' i) {7 P
  ;
% q5 V/ d7 b/ J4 i: q/ i& C( r( p  OpenCmdInCurrent()' ?  w" b6 C7 B/ P4 C4 ^
  {
; F4 y- X! w5 e+ X7 F  ; This is required to get the full path of the file from the address bar
) T4 b/ b: }- j/ U3 y2 e" Q  WinGetText, full_path, A  T! l* E$ Q3 A8 B) m' s' C
  ; Split on newline (`n)
6 g4 m: G6 T6 `; ^  j  StringSplit, word_array, full_path, `n1 b: l) ?4 ?7 j, p! Y* H: n5 ?
  ; Take the first element from the array
. Y3 [* f: p1 K5 b  full_path = %word_array1%
9 {" r. T- a! n$ p+ M# D  ; strip to bare address2 j+ m* o) R7 S0 A
  full_path := RegExReplace(full_path, “地址: “, “”)
, g3 k5 i- ^* k+ Z  ; Just in case – remove all carriage returns (`r)# T* T& j  {+ a/ R- B9 h/ D
  StringReplace, full_path, full_path, `r, , all
: D' f* Z5 S3 E$ z# a* s& I  IfInString full_path, \8 G  |% }: `; K  Z' B
  {4 A. o2 ]/ ?& m, V
  Run, cmd /K cd /D “%full_path%”% a% S0 j5 `) j, H2 r( }
  }; x5 n- I! R6 k9 d
  else$ g1 P4 k- l0 ]6 U% G5 K4 N- D" G/ q
  {
0 d( T7 ?) E5 n% i: M$ R8 {  Run, cmd /K cd /D “C:\ ”
9 E0 t2 m; [/ n  }$ D, \% b; Z3 k/ H: f2 Q
  }
4 ]- u% @3 B; D  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。) S+ ?/ g4 m: ?; g: `* q9 \" ~
  这段小代码肯能有两个你需要修改的地方6 |  _* ^% }- u$ m$ o
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键' v. t* z. g& l2 b# e3 N
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “+ l1 K, d- R+ g1 A0 B
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2025-9-7 05:08 , Processed in 0.061152 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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