电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。- R% i! C1 g9 W
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。
4 Y: V$ ^1 W0 e5 l2 a  方式一:- t& u: f" v8 A
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
5 n! O& i, j) f- j+ {  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和& b& c3 g) ?" {& P' \' g
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
) V) A2 t: @  R3 h  方式二:0 H0 C: K/ @: l+ n7 l% Z
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
! d4 T$ N6 d& y0 |* i4 |# r  SetTitleMatchMode RegEx& `: X& H6 @; K
  return( C& y3 l% l  v  d( A, {
  ; Stuff to do when Windows Explorer is open, U- ?+ d# W8 K5 |. X
  ;5 l# z6 `* e! w8 c+ p
  #IfWinActive ahk_class ExploreWClass|CabinetWClass, H2 m# a" |: Y6 s" T9 t* A& F
  ; open ‘cmd’ in the current directory
: q, v; F0 x- j6 `  ;, E+ U/ ~3 f* B2 u
  #c::
2 R6 `* e- S0 b" w: a; X  OpenCmdInCurrent()
( ]0 _$ N9 p6 u2 a  return4 l: \" I: K' _: y4 D" }
  #IfWinActive
) r' b' ]8 J; M. z  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
  H' L* s5 }* P" k( h# K- J  ; Note: expecting to be run when the active window is Explorer.
6 z: l# O0 A7 Y' f6 D' _0 R1 M8 b  ;
2 C0 O: m' K! N5 O, \  OpenCmdInCurrent()3 A" s: c. W) G5 z# [
  {  |6 D: m/ _+ C8 ~. W7 J
  ; This is required to get the full path of the file from the address bar; C1 I0 I4 a6 X0 I
  WinGetText, full_path, A
5 x* |& k/ y# W; P0 b' L+ l( Y  ; Split on newline (`n)
2 d4 h4 m8 V& o  t. l+ x6 Y  StringSplit, word_array, full_path, `n1 I: q# P: o% Q) s' `6 T
  ; Take the first element from the array
" \! n$ U0 J4 x' D5 ]5 ^  full_path = %word_array1%& p8 K4 n+ F3 Q3 ?( j6 j, \! {
  ; strip to bare address
, V0 Q+ g- l' C  full_path := RegExReplace(full_path, “地址: “, “”). ~. I- \7 m5 N$ e3 L, d" |* [' J
  ; Just in case – remove all carriage returns (`r): ?& b* ~+ _- b. m. P& M5 W3 Z
  StringReplace, full_path, full_path, `r, , all3 ?, B, h+ a6 ^
  IfInString full_path, \1 Z( o( E9 P! P' S; l0 u! S
  {
/ L* o- M5 f$ s# S0 t( Z$ \  Run, cmd /K cd /D “%full_path%”
9 n; h6 |$ ]9 y  }( W5 }/ e* Z3 \) i# h6 h
  else# i- N, `  ^% Q! W, l: r- X& X
  {# M2 ?4 z* g1 _4 F9 C
  Run, cmd /K cd /D “C:\ ”' A6 A2 e# [0 C5 L; r" ~$ `! @& G
  }1 a; r; O2 r3 m+ g/ O
  }; C+ k) A9 x" [+ D9 h3 s$ r4 j
  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。6 O! d4 ^; q" K  h( o- X+ H
  这段小代码肯能有两个你需要修改的地方7 o1 B# k6 H$ w  g0 |5 e9 ^) I
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键# V- O3 L  O& H; C: T
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
$ T5 \2 ~1 {/ p, a3 r8 u( {
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-1-14 10:13 , Processed in 0.053350 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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