电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。& r; ?( l- |# L4 ^7 p
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。0 j& e; {) n& |* w3 H
  方式一:2 C; d+ X3 `. ?& h; {$ j% j, E
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,' s& Y! V0 o$ n6 V. O& w, L
  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和9 h3 N1 Y% f7 Z, {5 T2 u- b1 t
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
( A4 |3 A; U5 s" q- P  方式二:
' t3 p+ q+ J+ c$ l* b# `  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
# k) x- `- ~9 g' s  SetTitleMatchMode RegEx
- D% B/ k1 m$ Y6 d1 W+ x  return
! V( P  n( F. O  ; Stuff to do when Windows Explorer is open0 @0 P5 m$ Y8 q, {' \1 f
  ;2 w( T1 U" V) E( ~7 C5 I
  #IfWinActive ahk_class ExploreWClass|CabinetWClass
7 m  t2 \6 K# N% _' b  ; open ‘cmd’ in the current directory5 v8 f7 e, G+ n! L
  ;) S+ {! n. P% ]3 X' Q3 v6 u
  #c::7 W8 E, r( o) t3 ~7 M  i' a
  OpenCmdInCurrent()
: ?, z8 Y/ S. X- V: c' ^  return  p+ d1 K$ L  S1 l& @
  #IfWinActive
3 j/ y5 A+ Y, ?) ]  d% A* A  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
8 n! M! n" B. F' ^1 \  ; Note: expecting to be run when the active window is Explorer.7 P6 \  h/ ~2 X8 u8 g+ `
  ;
: y7 h9 p2 s. ]  OpenCmdInCurrent()
4 L" f2 |2 M* K  _  {
; j) w6 y( h0 I" w- L0 a! Z' b) o  ; This is required to get the full path of the file from the address bar4 k8 }1 n* Y, {  N
  WinGetText, full_path, A/ }" k! w. P' ]& B9 f
  ; Split on newline (`n)5 b& f1 h6 h4 _
  StringSplit, word_array, full_path, `n
3 q+ G4 y8 ?" ?  I4 W7 M  ; Take the first element from the array
6 D) E/ G2 J, ]) a! `  full_path = %word_array1%
; M! W" L  L4 g/ x" w( F- o& z; C2 o  ; strip to bare address
( M$ f6 W/ z, y# Q  full_path := RegExReplace(full_path, “地址: “, “”)9 B9 [" _; n2 S( q
  ; Just in case – remove all carriage returns (`r): [) Z6 {2 L9 h+ Y1 d) n
  StringReplace, full_path, full_path, `r, , all8 d& o7 L2 j" r# e3 p2 r. C
  IfInString full_path, \" L6 C* ]. p6 ?
  {1 h( K6 l, Y7 Q( ~
  Run, cmd /K cd /D “%full_path%”
% d/ ]5 b! L/ ~8 \# M' R  }
( P& D2 m- ?1 n& c$ f. {3 E  else
5 J" U/ L9 H4 x2 Q! \  c9 p  {+ D' k$ R' I4 g$ c) u
  Run, cmd /K cd /D “C:\ ”0 w; m9 S1 e9 A6 l- K
  }  [: Q. D& q4 O( [- g
  }# d& @0 C5 W8 o3 N5 l9 t2 C, Z
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
* p: z+ d8 J4 A& ?) P" f  这段小代码肯能有两个你需要修改的地方
5 a6 v5 T! B. ^, z  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
& c6 n$ A. ]3 F1 t$ T* F& q  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
+ E8 A9 L8 u! |7 v% D' H
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2025-5-15 20:47 , Processed in 0.058247 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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