电脑互动吧

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

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

[复制链接]
发表于 2014-5-21 10:20:02 | 显示全部楼层 |阅读模式
  此文仅限于对经常需要打开命令行并且感到正常打开命令行方式很浪费时间的人。& {2 d0 b$ x# H- n. K
  正常情况下我门需要打开CMD, 然后再CD到自己需要的目录, 这对偶尔用用的人倒没什么。 但是经常需要这么些操作就感到浪费了大把时间。 现在提供两种方式让你像在linux中那样更高效的在当前目录打开命令行。; r5 p4 O) M* _; F4 `
  方式一:
' l% d: C+ H, a+ i  在当前目录按Shift+鼠标右键, 你就可以看到类似的在此处打开命令行的选项了, 如果你想去掉shift,直接按鼠标右键就有此选项, 那么你需要用简单的修win7系统改下你的注册表,
; h6 n6 T( S' n8 v( z  去注册表位置HKEY_CLASSES_ROOT\Directory\shell\cmd 下面将Extended键值删掉, 如果你还希望驱动器和桌面也能这样, 将HKEY_CLASSES_ROOT\Driver\shell\cmd和
, i% `: t1 }# F0 }; [0 o  HKEY_CLASSES_ROOT\Directory\Background\shell\cmd 下的Extended键值去掉即可。
0 \% G. m7 Q( p* S8 ^! W) _  方式二:/ c  g# U  i# `2 O# e3 U. {& x3 y
  用快捷键,当然会用到人见人爱的Autohotkey. 其Auothotkey代码如下:
+ `" n1 a2 l8 ]! |9 I3 ?  SetTitleMatchMode RegEx
! l3 O9 W0 G7 d5 M2 i% f+ e( Y  return
5 S2 L% |$ J# r; F! [. l  ; Stuff to do when Windows Explorer is open% s4 x+ ]: Z1 x8 P0 r, x( h
  ;) K- G8 y' |" m
  #IfWinActive ahk_class ExploreWClass|CabinetWClass
2 [: \" P9 ]: v8 Y8 A  ; open ‘cmd’ in the current directory4 l) a) K0 [5 l! R# d1 v0 G
  ;
- `7 B  [" a4 R7 z' }  #c::- H; p/ D: _: O5 J+ B$ r$ }
  OpenCmdInCurrent()
* }- e, a! J% j9 ^  [- L  return( W8 C( E7 s% |3 p/ Z$ G8 A
  #IfWinActive
6 E3 ~% a, ^- m! M5 @  ; Opens the command shell ‘cmd’ in the directory browsed in Explorer.
$ {7 C6 w4 i4 F1 {, J3 F  ; Note: expecting to be run when the active window is Explorer.
" R; M- c' G5 X  ;
' L# E- x2 J! H' k7 @  OpenCmdInCurrent()
& y3 q+ k( B' \3 [3 L9 M* v( D) d  {
% P9 V' |# d# ]) U7 k- k* x4 V  ; This is required to get the full path of the file from the address bar2 x$ p# G$ X( p/ u
  WinGetText, full_path, A
8 `0 b  ^! D0 K, v3 q% y9 i  ; Split on newline (`n)3 W: ?7 ?3 n' G+ F
  StringSplit, word_array, full_path, `n. f( Y8 T8 Z3 W5 @8 k( n
  ; Take the first element from the array
3 L8 [4 {3 p/ X; q' f  full_path = %word_array1%
7 V- \( u  F+ F2 D1 i" D8 k  ; strip to bare address- T- D+ |$ X$ k1 }6 y
  full_path := RegExReplace(full_path, “地址: “, “”)
! M( Q$ Z6 {% [0 h  ; Just in case – remove all carriage returns (`r)" b, T) R2 q! g& l7 d
  StringReplace, full_path, full_path, `r, , all
4 ?  f3 y! |. Q9 T- B( n! y  IfInString full_path, \
: \9 p- X/ m2 K; Z% M8 N! E  {
: ~) O; \& P5 Q& q% G& M  Run, cmd /K cd /D “%full_path%”
1 i/ r2 w4 k& G9 T( P. j5 _2 G  }
* w1 h6 J  a$ R7 X* x  else
* v) l1 d1 ~2 H, w  {: m. L7 ~( g% ]1 l+ ?& P
  Run, cmd /K cd /D “C:\ ”' J3 J, }, C: u# z
  }
! j, c/ k0 K. M  }
0 W# v* O6 I8 E  把上面代码存为UTF-8编码格式(因为有中文)的ahk格式xp系统之家,用Autohotkey打开,然后按win键+C就可以在当前目录下打开cmd命令行了。
# i  L4 l& m4 ]9 o; t' ]! L, }  这段小代码肯能有两个你需要修改的地方( z7 A0 i2 c5 d. S/ D  U
  1. #c:: 中的#代表win键, 这个代码中使用的是win键+C, C可以改成你需要的其它键
( D$ [2 O! i3 w# d+ p6 ]- h  2. 如果你的系统是英文的,你需要把”地址: ” 改为 “^Address: “* a$ X5 m2 c$ M0 f$ I( X
回复

使用道具 举报

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

本版积分规则

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

浙公网安备 33032402001025号

GMT+8, 2026-1-21 18:23 , Processed in 0.058449 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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