电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
$ s. B6 S* h7 ]5 z  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
6 o( ~- X0 q1 v2 j2 w0 {" P8 \  方式一:
. l  P" R2 H! [* `8 ^# s  O  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,8 F+ `' C8 ~: t
  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和5 F$ g) O2 |( ]" G- f2 d
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
4 f2 p; _' H" x' s& F" n7 G  方式二:
! y8 s. `4 B) r& p  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
; W3 |9 H2 o+ c9 P' u) x  SetTitleMatchMode RegEx
1 ]' M$ w9 p  r# f  c  return0 r$ z, p+ [# W  U' {
  ; Stuff to do when Windows Explorer is open+ w! }# Q0 e6 v- z
  ;8 V7 d9 ~3 b' S# L( c! U5 e
  #IfWinActive ahk_class ExploreWClass|CabinetWClass2 d) P+ B8 ^' n1 J3 a6 {
  ; open ‘cmd’ in the current directory
0 @( s3 ^5 r9 v9 H# `& U) _  ;
* c. ^- R6 a3 t  g  #c::
; `; t5 E7 ]. A% Y. ~. a9 R  OpenCmdInCurrent()
3 m3 X; [' v0 \# I# u  return
" c; g7 ^. ~2 L( B  #IfWinActive
0 P8 Q* t% N0 g, r- U+ u  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
; R8 A# y6 _( G* \  ; Note: expecting to be run when the active window is Explorer.6 h0 X4 _2 _9 B$ i! ^4 e& F1 f4 f
  ;
8 m8 u+ N- r  d( g7 V+ T. e  OpenCmdInCurrent()
1 ?3 n4 o! u% S2 X# Y  {' F- ]. }' v: L4 ^; s4 Q2 t! b8 D
  ; This is required to get the full path of the file from the address bar6 g, {5 Y) m* {
  WinGetText, full_path, A
: K8 k5 v3 t1 x% z, l  ; Split on newline (`n)3 d& ]8 q2 g) A, b7 z- B
  StringSplit, word_array, full_path, `n4 u4 l$ b2 H  D0 y. O# x. j
  ; Take the first element from the array, ~: I8 a7 g7 ~8 K
  full_path = %word_array1%/ b3 y2 V9 |5 |: i
  ; strip to bare address" E" ^! d3 S- r; @& y
  full_path := RegExReplace(full_path, “地址: “, “”)
1 ?( ^$ s$ a. ]8 E% O  ; Just in case – remove all carriage returns (`r)
% R) U+ l! A" S3 E) C# g  StringReplace, full_path, full_path, `r, , all
, m- l) G4 `3 N. _9 ~9 P; ?; @  q  IfInString full_path, \
9 U/ @! e; ?+ L/ ]( g) a  {* `- E" X  v& w
  Run, cmd /K cd /D “%full_path%”
/ b/ g# U# P) r& F. ?  }
9 J% ?, D1 A$ w# O* m; P) T, p  else! T2 r3 ?+ Q$ R
  {1 r7 d; I1 N- }* e+ [0 j
  Run, cmd /K cd /D “C:\ ”
& |: t: }  E6 `; L! u  }# j! M$ P0 h/ A) B5 g3 B0 t
  }
: p9 X3 r$ ~6 ?" _' R8 R' k  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
9 y, ^; ~$ Z8 @  o9 J  这段小代码肯能有两个你需要修改的地方
+ h6 G5 ]) M5 |$ d# M* J, ~  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
9 d) }5 M; C- C) P, A% r/ O  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “; S" o# a8 y3 L
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-7-15 09:05 , Processed in 0.119130 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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