电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。0 ^3 \4 m% ?- D% m+ {( L1 ~, V" ~) M
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。& j; T" O4 }; s7 j& v, t! v
  方式一:3 c$ R! W! ]# o* O* ?# i9 k
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,' a9 b& I1 a7 }
  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
( X4 X$ ~7 a9 k2 {# y6 e  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
8 z. H1 l' q1 G0 T8 f1 N) m  方式二:. S1 o1 o/ a8 M" q& r' Y; U
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:/ `$ ?, @, g6 o+ b
  SetTitleMatchMode RegEx9 n+ d% ]2 ~; j# [) n9 t
  return
' q3 J  m" a+ b* ~: @7 h- A  ; Stuff to do when Windows Explorer is open
2 {# }+ B  }% Z# O7 [  ;, d" c* F+ R( B8 ^; x" l, B
  #IfWinActive ahk_class ExploreWClass|CabinetWClass9 G' |( i- }# B0 C3 h4 S* z5 {* R
  ; open ‘cmd’ in the current directory
* e9 Z) y( X: c% P7 a  @1 m5 z  ;
+ Y1 z% `( ~0 M! u8 r  #c::  U# {" @# v. G) z
  OpenCmdInCurrent()* s# G4 J0 D# O( y% @+ E% O) u
  return$ E2 @* f# H% w  V3 e" [2 A, U
  #IfWinActive
6 Q5 B8 x$ ?+ J: w; D" g. p0 k/ k9 e0 Y  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
+ a: a0 Z  }8 v( i1 L; [$ I  ; Note: expecting to be run when the active window is Explorer.
1 _% G# y. P# }% @" j2 n5 ?2 I# M  ;4 H3 U2 Q0 V, P# A' Z3 C1 r- ?
  OpenCmdInCurrent()
: s" p8 W, d# J& ?$ [6 E  {
9 D0 z. U3 f9 ^4 ?; K8 f  ; This is required to get the full path of the file from the address bar* R  ~2 C' S# |6 a3 _( ]
  WinGetText, full_path, A& N9 Z' f' ~. A# @" [8 C& h
  ; Split on newline (`n)
1 `! H' {; H- t7 |$ r  StringSplit, word_array, full_path, `n
" n' r8 B6 S& H) M' Q2 K0 |, i  ; Take the first element from the array
. g0 Q* {% D) s0 U9 ^/ D7 f  full_path = %word_array1%' [$ }7 C5 F- C0 P; {2 K0 ?  j
  ; strip to bare address
2 {/ n4 n* ~* q3 o* a* T  full_path := RegExReplace(full_path, “地址: “, “”)# t7 S, x, i( a) n
  ; Just in case – remove all carriage returns (`r)
) O5 a4 I6 Q: A; ^3 Q  StringReplace, full_path, full_path, `r, , all; P/ l+ K" ~) N9 }0 w  ^
  IfInString full_path, \
8 L" o8 O: ^" M$ U7 c* }  {
: z' r0 Q% T- a% I  Run, cmd /K cd /D “%full_path%”; D7 a' j2 g( f& t, ?
  }( J% m! p2 A# C; V! J0 |
  else
" X5 L6 {! U# O) F8 D+ T. ^; E  {% A* \) H- h& ^: k5 I7 o
  Run, cmd /K cd /D “C:\ ”
. F9 x+ R3 e$ @  b0 j. {  }! O* H$ p- k; V+ |- k7 e
  }  y9 i- M' k8 @& j2 T4 a  f
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
$ _! S% ?+ t5 e! a) S  这段小代码肯能有两个你需要修改的地方2 h# q# }' d4 I; e
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键6 Q. y! E( c& i: [; D
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
% ~& T# f2 c6 ?$ e% j& z0 y+ ^+ M
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-1-19 12:39 , Processed in 0.095213 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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