电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。7 U  I4 h6 V) c
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。9 Z1 A. X. w! f8 A7 Y* U! P5 `
  方式一:
, F" E" I% c0 E( R3 r4 p. R  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
7 Z0 J' L. u& D' t3 r7 e2 S  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
7 p! ?. u/ \; r( p& A( K  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。! r  N) h" u' o$ a1 x
  方式二:
, V8 {* h# G) q/ n  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
8 M8 L3 n/ ~. \+ K" Y  SetTitleMatchMode RegEx9 O$ n) W$ A, V! i, X* c8 ~' }
  return# d/ @- X8 M7 ?% m$ A
  ; Stuff to do when Windows Explorer is open
4 Q: Y# |7 _" i  P7 e0 F  ;
" n  [9 t$ ]. I0 Z! t  #IfWinActive ahk_class ExploreWClass|CabinetWClass- W7 s9 Y9 N% v, I% [% A
  ; open ‘cmd’ in the current directory
* Y; v" C8 z2 l8 g/ |6 l( C- C" G+ J9 A  ;
% D6 N% H! f$ U  #c::. E* |$ w- ?% i% |1 d5 J; H
  OpenCmdInCurrent()- G, ^9 C  g& E/ q* k0 n+ d8 V: [
  return
+ q  ~) s$ x- R$ o; ?3 y1 h  #IfWinActive8 r9 k5 d2 d" ~* A9 _$ c
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
. y# X1 W8 l  `7 w0 V; D  ; Note: expecting to be run when the active window is Explorer.. I8 p1 [$ ]. t
  ;
8 w6 T& q, w0 k; j7 h  OpenCmdInCurrent()# A& e% c; t; h7 C/ f% u8 b
  {6 {3 n2 |; g6 X/ [/ s0 B, g
  ; This is required to get the full path of the file from the address bar
) j7 H1 M8 q2 ?# R0 p" u# p  WinGetText, full_path, A
) g6 M" c. A& p. f% |9 I  ; Split on newline (`n). o4 b+ Q2 l! g2 E# {' S* I
  StringSplit, word_array, full_path, `n/ _: q) ?' e0 r* P! u/ j9 X
  ; Take the first element from the array
2 E2 ]( X8 Z# _  O  full_path = %word_array1%
4 @+ Q2 T1 ^9 ]' W6 h( c! P  ; strip to bare address8 n& H& S$ h+ @; j( N+ ]
  full_path := RegExReplace(full_path, “地址: “, “”)
  u  W7 K2 x% t5 [: _9 h, X  ~' k  ; Just in case – remove all carriage returns (`r)$ y; A8 ~* z  y: u7 ?# O# l8 G
  StringReplace, full_path, full_path, `r, , all' @# u1 j5 F- r" J5 E3 d* c
  IfInString full_path, \0 G6 \; G  Q8 }. o" I6 X5 u4 X; s
  {. k1 }& }1 l. J9 p6 T
  Run, cmd /K cd /D “%full_path%”0 [% `6 H% F9 z1 n5 N: Z
  }
/ {. ~% |9 I. |  else
7 I8 ^4 R( i& n6 ]5 o* r9 q  {4 F, W2 a! [* g. A+ m7 D
  Run, cmd /K cd /D “C:\ ”1 \( K% `) n1 K! l# [3 u; G6 @
  }" r! _2 v! z4 g6 b& G6 u
  }9 |5 q2 N% }' M7 `7 S* L, D
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。5 a' E% ^! S- P0 B2 P0 v8 p
  这段小代码肯能有两个你需要修改的地方: e4 p  F6 m0 T7 `1 j0 d2 Y
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
' I4 b% s/ ^9 c( s' [- j- X  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “/ n: y5 [, K. M0 y0 f& a( T9 R
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-1-13 06:50 , Processed in 0.053263 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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