电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。% E2 l* k+ r( O
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。$ ?; N  o* e; W. i
  方式一:( [  v5 k+ }3 H5 `, k" l% L. ]
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,5 y! x% E( ?8 ]7 Z- t" Z
  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和0 U( }0 u6 C& u( a5 Z
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
0 j! v0 N' s* ~9 {  方式二:) H& S+ b2 D$ G* Q% I  S- t
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:9 e% Z( x$ a/ y! F
  SetTitleMatchMode RegEx! l* H/ I+ V! W  E/ t+ u. b) E
  return$ w: B- u  \8 W
  ; Stuff to do when Windows Explorer is open0 n% H3 W1 g+ g" F1 `5 P. B
  ;
7 j9 V" D$ [& A4 Q3 t  #IfWinActive ahk_class ExploreWClass|CabinetWClass6 J+ {" N; P' S$ ]2 h( Z( x: i
  ; open ‘cmd’ in the current directory
$ i! k3 Z# q, g, [) z6 k  ;
' Z4 a2 q5 z, H  #c::& e1 {' t; f8 Q$ V; z) K
  OpenCmdInCurrent()
% T+ x; \- S) `8 a. `- c) H  g* Q; i  return2 N# @) c* ]! \: K0 @* m
  #IfWinActive" L/ P# `" y& Z
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.# `) D/ M; F7 }2 {3 Z! ^$ I3 j
  ; Note: expecting to be run when the active window is Explorer.
( [  r/ e& G, T) `; b. @" t  ;
$ z. J) Y* R6 ?4 b$ ^+ q  OpenCmdInCurrent()
) ?  ~# o% l4 }2 h7 Y) _: S  {5 F. A$ B2 b7 p: |: U
  ; This is required to get the full path of the file from the address bar0 @$ O7 D- ^& i! y, C  x/ S% _1 i
  WinGetText, full_path, A5 K6 ?# N6 ^& M8 v6 B
  ; Split on newline (`n)
9 ]$ c8 F; |4 \" s" S6 E( R1 v  ]( p  StringSplit, word_array, full_path, `n  I5 f- H/ D* T, h5 r8 c$ o
  ; Take the first element from the array1 K: s9 |8 ~7 {4 d, V  D! A; D
  full_path = %word_array1%
& t( U3 D+ h4 J$ R! `, k' h; l  ; strip to bare address
9 A4 F8 n. F6 A4 B0 G  full_path := RegExReplace(full_path, “地址: “, “”)
" i7 G3 y$ h/ Z  Q2 E1 S  ; Just in case – remove all carriage returns (`r)
. ~4 d3 y" Z2 |. Z1 h' W  T  StringReplace, full_path, full_path, `r, , all
/ j5 _, }: y& B8 C7 R  IfInString full_path, \
" Z) o# O6 q% A  {
8 ~+ g$ p  v$ k+ P) J- q: D/ b; V  Run, cmd /K cd /D “%full_path%”
% R& J& S1 k3 \& X0 x  }
3 D( O" V/ ~: H1 R, E; F: C; M  else
# X. g. [1 x, M7 M' |8 f  {8 H. N% m# w! u& c" t4 p/ }' [
  Run, cmd /K cd /D “C:\ ”
3 c# x# C. q# j$ e% k  }( c. a2 Z6 l3 L" ~
  }
3 P- E% {6 u; h. U4 Y  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。+ i$ P% `- }  K! d3 a
  这段小代码肯能有两个你需要修改的地方
' c/ ~, U' l! b/ A1 |  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
' a) \* c8 X$ A* M- c5 ~) [, |% c  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
; B5 ?; Q2 u4 Q
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-1-26 13:03 , Processed in 0.071199 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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