电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。2 a  \( {* A; f/ `1 w4 c' R
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
4 B. s7 O( d# v1 k7 g& O. w$ ]+ |  方式一:2 O! `9 d2 F8 U* m
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,, e9 C9 H  {; Q8 C) P9 B
  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和% t. \8 H0 o# _1 \
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
5 t- a: Z- D7 j" M  方式二:: I& X: l* V( y) Y0 `
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
5 y4 P+ }+ `2 \, S  SetTitleMatchMode RegEx
) j: h4 m% q7 Y  X  R  Z  return% e6 H) c& j9 O) U) O7 `5 O2 H
  ; Stuff to do when Windows Explorer is open
- {/ _; _) O7 z$ `0 E) h& U  ;
0 \8 [: p  n9 k# s& V! O  #IfWinActive ahk_class ExploreWClass|CabinetWClass/ a) {, }$ Q6 k& x  I% d
  ; open ‘cmd’ in the current directory: `( n; u% I1 a7 e# V! o6 a4 R
  ;, ~& t5 z$ b  I
  #c::
) ^  {  u0 j8 c3 _7 \  v6 @" n5 o  OpenCmdInCurrent()' P; x& E. z8 `* ~) L; I. F
  return# O8 O/ T; o) W% K# C
  #IfWinActive& T5 @9 Y/ A/ R. D* Z7 r
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
; C$ ?8 w; T7 U# ~9 R( A  ; Note: expecting to be run when the active window is Explorer.* E/ Z) |0 `% v7 h$ }
  ;  ~0 A, k( V0 B8 y* Q
  OpenCmdInCurrent()% s7 n! y3 y% A
  {, e8 ]( c- ]- Y6 _3 w) |7 `
  ; This is required to get the full path of the file from the address bar
9 S9 [2 h! G7 \# A! o2 g$ W  WinGetText, full_path, A* b% @$ Q% J5 M" z+ j, h6 I4 T
  ; Split on newline (`n)
" m* W2 {0 N: a! h  StringSplit, word_array, full_path, `n
9 M* R% p9 S! b; B  ; Take the first element from the array
% K# g- M% h* p, _  full_path = %word_array1%/ N2 e7 @7 F3 C( J8 g6 D1 X  h2 e3 x
  ; strip to bare address- x( C& o: y: v6 }
  full_path := RegExReplace(full_path, “地址: “, “”)
/ N! z  y8 ~  f4 M  ; Just in case – remove all carriage returns (`r)
, }7 m' L/ t, e9 v: K  C; D6 b5 e  StringReplace, full_path, full_path, `r, , all) I+ [1 t, D& z0 c& E5 \4 d' R
  IfInString full_path, \
/ g, H; f4 j5 }( U% U" b1 ~4 h  {
3 h/ ]+ w- K1 O. {  Run, cmd /K cd /D “%full_path%”
. i) x* [6 q9 m0 J0 x  n4 k  }; r$ Y3 g4 J7 l1 `) B
  else9 E2 a( c' F9 ]( T/ M+ O
  {
0 c6 Z( F6 ~5 G' j, n. l8 }+ a  Run, cmd /K cd /D “C:\ ”1 `6 o6 s1 Q8 S
  }. a) V% b4 L% Y" n
  }- a: o& E) W: x/ O
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
7 _7 |0 W- R" z' Z: \; R  这段小代码肯能有两个你需要修改的地方
( j' s5 U2 I! \  g$ a6 K$ X  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键! G! L2 _* z5 b9 _
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
6 }5 T- y4 E1 l/ ]5 @
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-7-24 16:50 , Processed in 0.065082 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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