电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。
; m3 o# N. O) T* n% r  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。# k, n/ V% {. s
  方式一:
" O" a, _7 K! T1 ?  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
" D( E2 m0 k5 ]6 y8 T6 G: i  S! C: s  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和9 c! S: @5 F  e- F# `( B2 F
  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
6 g. k  _6 {* c/ G% z  方式二:
. j  U" ]- \5 ]  a  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
  n7 _9 z/ m+ t; ~! W  SetTitleMatchMode RegEx
* ^% W: v- ?! L& g  m1 _  return
8 c- N/ o5 h2 ]/ |- l. v3 M  ; Stuff to do when Windows Explorer is open' n5 Y8 V8 N0 ~
  ;# Q0 \" q$ Z! H' l: V" }' k' G+ M
  #IfWinActive ahk_class ExploreWClass|CabinetWClass
5 t% Q# c/ Y5 ?1 h  ; open ‘cmd’ in the current directory9 n0 B6 ~+ a8 f* v; j- X  e, N- y+ i
  ;+ u& H1 G9 p6 u6 o- E0 t! j
  #c::
2 {% l( E4 A6 a  OpenCmdInCurrent()1 ?7 L: j# f' R* u, T7 X2 V- i7 ^
  return
1 O" Q% H" b3 V  #IfWinActive- {% K% a+ }$ e
  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
- P- @$ L6 _" X/ ~% v! P4 g" J) X8 ^. L  ; Note: expecting to be run when the active window is Explorer.1 H) W+ X  u) T7 r! n6 `
  ;
3 @) g! f0 T1 w' I  OpenCmdInCurrent()/ c$ M1 y1 z" D1 ^9 z" f, h* g
  {
; s" X+ \, H9 `- v8 {' B2 Z* K7 B  ; This is required to get the full path of the file from the address bar9 [# F. ]3 A5 G" S
  WinGetText, full_path, A" d: C+ r% w7 B7 D: r
  ; Split on newline (`n)* {* k1 e& e" B) c# g
  StringSplit, word_array, full_path, `n
9 R  |/ T( t: g+ Z$ B, t# N3 j) J  ; Take the first element from the array
0 p# R) D- J$ O  full_path = %word_array1%; V9 [5 s7 \- R" P, @
  ; strip to bare address
5 {' f. G  s: M$ e; o! X! H% R  full_path := RegExReplace(full_path, “地址: “, “”)
# f- g# T5 B% @* a- Q! A  ; Just in case – remove all carriage returns (`r)3 E) s4 x7 ^8 t4 W( k$ q' B& j/ a
  StringReplace, full_path, full_path, `r, , all# }5 T( K3 X5 g8 C% O: M6 j$ n" f
  IfInString full_path, \
4 Q2 q( x! N0 U" v; H  {
# y2 X* p5 H3 i8 T$ g0 _$ z0 p  Run, cmd /K cd /D “%full_path%”
+ T0 z. e: p! Z$ c. J( f6 `  }2 h5 ?& H6 U6 e. X* w( N8 s
  else
6 p7 z. N! n* o7 ]& {3 O  {
2 _: x# c. @& e  Run, cmd /K cd /D “C:\ ”( u& ]: ?7 ~4 r5 y  S1 u9 X: s& [7 _
  }( {1 f; u9 j, Y0 O1 ?; N7 E* k: b
  }
& N5 n) T9 |3 F' j8 h  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
% o# K# Z* i2 ^+ G: X  g5 N. f  这段小代码肯能有两个你需要修改的地方
/ I& d5 l9 q4 e- M  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键8 V  P  b1 D2 n& [/ m) E
  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “
( g; F& D3 p. S) J! c+ N
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2025-9-17 03:44 , Processed in 0.055762 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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