电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
) C) D( ~# G7 l) W5 ]2 N6 ~! c% p  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。$ `( x3 g: R% `( @7 {
  方式一:
6 _4 \+ i: y& J$ ^4 I  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
4 |: q0 B3 a1 R( z  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和+ l- t4 A0 I- s2 P7 O
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
: j. n" V1 l5 D/ |: `  _3 S  方式二:' U; v2 i* V% I% A1 N' P- h
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
- d0 ]/ {: ?7 z1 h$ ^, o  SetTitleMatchMode RegEx5 i) C; M+ e; P+ d! k- d0 K* ~7 Z% P
  return4 ]$ m4 e, w2 U7 U7 X6 k
  ; Stuff to do when Windows Explorer is open
  m# Q  B; B3 g& B/ Q. s  ;7 J7 n! O% k# s% t4 {: j
  #IfWinActive ahk_class ExploreWClass|CabinetWClass7 t$ y4 }! [5 Q
  ; open ‘cmd’ in the current directory
$ i) ]/ r/ S2 G4 \  ;
& u& \1 v: I$ D" ]6 u0 [  #c::( N* e1 j5 M  e1 Q1 `9 A
  OpenCmdInCurrent()8 Z3 ~% P$ H5 Z+ z
  return5 w1 z& [( f5 j! ?6 o
  #IfWinActive
+ |6 ^' w7 ~2 @$ W; ]  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
4 c8 ]5 h8 l* L9 m  C* U  ; Note: expecting to be run when the active window is Explorer.# h+ f! \, f$ L. u
  ;
# _5 T; K2 R, z7 u! S  OpenCmdInCurrent()" c4 e+ `* f! S, Q2 x
  {: W" e3 i; W; I' ?/ J# @& k
  ; This is required to get the full path of the file from the address bar1 _$ r9 ^6 T5 f- L0 U% B
  WinGetText, full_path, A
/ |( u. M5 R; e, i  ; Split on newline (`n)& K7 b! Y, `/ [- b
  StringSplit, word_array, full_path, `n9 k3 t5 d/ L! _- }
  ; Take the first element from the array
2 d1 s1 _4 Z9 G4 g+ \3 d  full_path = %word_array1%4 l8 h$ a. p( b
  ; strip to bare address* G* v/ \6 I" e! k4 }. w% d: y$ ]
  full_path := RegExReplace(full_path, “地址: “, “”)
1 R  d6 Q$ @4 w  ; Just in case – remove all carriage returns (`r)
. f7 c' @) N8 ^* u8 X+ {7 m$ t; C8 O  StringReplace, full_path, full_path, `r, , all
: N# h1 ^6 q9 p6 Q) F  IfInString full_path, \
' ?/ @5 X, s3 O: A7 Y9 e  {
0 X3 N$ N- T1 r7 @9 `+ W  Run, cmd /K cd /D “%full_path%”. a. a; u; s3 g$ K# U2 L) Y- s5 c) x
  }
( w9 {; N( [, Q/ }) g) S  else
4 M9 s/ N/ C7 p# L+ X/ [/ b  {
. i# K: d: t. U) q9 y6 u  Run, cmd /K cd /D “C:\ ”
; I! I- F3 L2 ?8 Q# f  }
$ d1 Z/ F; K7 O" |2 [+ t  }- ~2 L- m( |7 t$ x+ N6 J+ Q8 N
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
: U# M* B8 g8 Y% j8 s  这段小代码肯能有两个你需要修改的地方3 I* F  ?6 I1 ?
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键( x2 {: _0 B, f5 k6 `9 V
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
' P$ p( B& T2 G6 g
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-7-23 09:06 , Processed in 0.057445 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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