电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。1 m7 D* e, u# x
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。" M6 A( m6 s6 C: r  u5 L; ^. D
  方式一:& [" [) X' y1 A/ \$ n2 {6 ^8 C
  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
% v3 f: N& \. f/ }8 r( {3 F, {  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和' c# N+ U2 E( h! E% A) s
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
" M" P$ D5 w- m* A( I7 ?  方式二:6 O4 F* i, f8 I3 a& h- K$ I
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
: W' }/ I" M: a8 x) o  SetTitleMatchMode RegEx* Y4 x- i: |# b' l' s1 g) K9 x' h4 [
  return- I& N* a& d# L
  ; Stuff to do when Windows Explorer is open$ r1 R1 V- C# X3 ~; z) t
  ;
! D- J: X, k7 v  j  #IfWinActive ahk_class ExploreWClass|CabinetWClass
. ]3 \9 d& z$ R( |' M. T  ; open ‘cmd’ in the current directory
6 h: H- f% Q$ v! b  ;
. `4 W* t" Q* j* h7 ~9 Q8 u  #c::
0 s2 n$ e. w. e! ?6 ^5 Q  OpenCmdInCurrent()8 ?- R# P! _1 ]) f5 ^
  return& b! {, d, u# {7 _$ R
  #IfWinActive7 x' q: C7 s  k- A
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
& O6 g6 x& z' B0 ~) R  t" V+ ~  ; Note: expecting to be run when the active window is Explorer.+ n, P- Y+ c) N/ Y
  ;& S$ q% y/ O$ ?4 g
  OpenCmdInCurrent()
5 z) S3 T" v: k5 J6 o) d  {9 [2 e0 ~! p# u* ?5 _' ~; f) a; m( b5 H
  ; This is required to get the full path of the file from the address bar  g! n9 m8 e" q8 e, D! M' p
  WinGetText, full_path, A' e) \( ?- F0 m- N
  ; Split on newline (`n)
; L6 E  ~+ m4 q- C$ C( b# `/ [# E  StringSplit, word_array, full_path, `n
8 L5 ^- h7 Z3 _) m- |9 b  ; Take the first element from the array
. h; B1 h6 S( J9 n9 _7 v7 i" L  full_path = %word_array1%
/ j4 ^6 u4 d0 y, }  ; strip to bare address% [! A6 Q1 K, q$ T4 y( x0 ^; C6 ~: j
  full_path := RegExReplace(full_path, “地址: “, “”)
+ i7 m+ y+ F1 ~! E& a% t4 Y. Z  ; Just in case – remove all carriage returns (`r)
4 C$ o7 z0 [8 F8 f9 k  StringReplace, full_path, full_path, `r, , all
  O; ^2 H* `: J" z  Z9 g  IfInString full_path, \
! Q. R, l# |: q0 [, @  {/ r6 Q3 ]. T  c7 \/ n( `$ h
  Run, cmd /K cd /D “%full_path%”2 B- k: _! G: a# L7 t6 R, x8 `
  }; t9 N& a* n  Q0 X' v5 q# p5 i
  else
9 V; m- E4 g7 h7 T, M  {+ A& r* U) A8 N" b7 W
  Run, cmd /K cd /D “C:\ ”
, T( }& [: G' N+ w, F  }
, b- H6 I( E! R8 c  }
  Y- q+ M% ^/ }5 O  ~$ F  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。+ H" G' m3 H  ~# j9 ^% s3 d- T6 ]
  这段小代码肯能有两个你需要修改的地方5 F+ I3 K: V/ R  T7 e  a
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
+ n& W8 U1 M  L  G" L  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
9 F1 ]* z8 c& q/ d! i) l4 d# u
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-6-16 21:36 , Processed in 0.057919 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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