电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。7 v/ q! w; h1 R, e: d& F6 y/ K2 {
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
6 ?9 L; H+ B7 M  方式一:- _; ?0 N& E1 c3 ~: ?1 A
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
2 D& B; [# r$ r: A  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和$ j( Q' @! _* @# i' n
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
; H+ G, Q$ Z: ?2 Y6 G' K1 e  N  方式二:
( _" B" P- G. I/ G) w4 i5 e* v  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:. x9 I. ^/ q  ?/ s# @3 f
  SetTitleMatchMode RegEx7 y# K. g* A) t- T- b3 ~
  return
2 j3 G6 R# V) ~- }: }  ; Stuff to do when Windows Explorer is open4 X) e; y; g5 Y. u  A% y  X
  ;
% s2 ^) u5 f1 b; i  #IfWinActive ahk_class ExploreWClass|CabinetWClass
1 u5 W- @: B" [  ; open ‘cmd’ in the current directory
( X% ]5 D$ V/ Y  ;0 w& n, J2 N% ^8 Y+ m; n
  #c::9 O2 h* D$ t% k9 ^8 A# }9 G
  OpenCmdInCurrent()( X: C' {  [, V3 y% L( |* q
  return
( H+ {! |* `% O0 s9 Z! s  #IfWinActive6 C9 a$ W/ X1 c
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.9 U- I! k3 _! s/ a: Y
  ; Note: expecting to be run when the active window is Explorer.' ~6 ]6 q: }4 L! B, Y5 p
  ;
7 r% K# w/ w- P  OpenCmdInCurrent(): p/ _# f! M3 k' o
  {
- P$ {0 c+ q, s# s5 q  ; This is required to get the full path of the file from the address bar
/ z# ^' b, Z8 Z* h3 Z9 j  WinGetText, full_path, A: ]# L8 u* R! p% m
  ; Split on newline (`n)) j. O% G( J3 e: V1 j0 g
  StringSplit, word_array, full_path, `n& k3 D: Q* s# d
  ; Take the first element from the array
8 ^4 F$ H7 ?+ F( D, T0 w  full_path = %word_array1%
" W6 p' n, h5 |1 @6 f  ; strip to bare address8 P6 I# z' p' E9 q6 f9 F2 n' z
  full_path := RegExReplace(full_path, “地址: “, “”)& j1 O3 \: W; H/ m0 W) S
  ; Just in case – remove all carriage returns (`r)- w0 x% f) i! a" D+ R: U4 E
  StringReplace, full_path, full_path, `r, , all  p; \- C: S7 P) ?/ x$ \! j3 J/ e2 P" \
  IfInString full_path, \
$ X8 g6 ?) u3 [  {1 E( l( Q# Z& b( s
  Run, cmd /K cd /D “%full_path%”
! g" z8 z  t7 F- B% z  }
5 A7 N1 B; q; n3 Z' H  else- ?) N7 c8 _" Q. a: C( a
  {
# t7 P4 v- n; U: R6 o. _! _% E% {  Run, cmd /K cd /D “C:\ ”6 a( K- Z, L3 P- G7 a
  }/ b; e: w- s7 Q7 S. J/ ]
  }
- E& [( ~9 v" ?/ ~) P/ p  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
6 V5 Z# M, E1 h1 Y5 ?; i; S  这段小代码肯能有两个你需要修改的地方* ]+ ~4 C; Y6 C0 r
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
, a7 X, U7 u- i0 ^& n  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
- n  T9 }5 y2 O$ t" M
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-5-11 06:36 , Processed in 0.125832 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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