 鲜花( 3)  鸡蛋( 1)
|
方法一:NetSH大法~
" Y' W( H: e7 m# O* p" G5 i采用下列Netsh脚本# \3 \3 r# C, a/ _9 Y. X% _
interface
$ F. @ {! G) c; Fset interface name="Local Area Connection" admin=ENABLED/DISABLED( R$ @* s* u" e( Q- W
7 m6 ~" Z) ?' g; N" D" K+ w: k# t. l方法二:Powershell+WMI大法
4 c& ^; _7 ^! g$adapter = get-wmiobject Win32_NetworkAdapter -filter "NetConnectionID='Local Area Connection'"/ b" n0 O2 A; T# M9 e$ T
$adapter.Disable()
: }. R. I4 P* ]8 T4 t) K/ T7 B( j: Q! S, i
同理可以VBS+WMI大法~" k: n, X. B* @# S2 }5 I8 ^4 x
这个就不说了~没啥意义了~
& @9 X: I3 L8 S3 Z
) v: }6 y( d% `5 X9 K' y其中有一个非常重要的问题就是权限控制问题!, S# `2 O a2 B. J; {/ V% o
Windows 7的UAC很严格,不能像WinXP里那样随意修改系统设置而不通知用户。
, q8 d, c! I- k9 [9 ]9 L: J7 \如果不赋予脚本执行环境以Administrative权限的话,脚本会执行失败,WMI返回码为05,Netsh报错:“An interface with this name is not registered with the router.”, q; g* x& A4 e8 }9 V, c
因此在启动Netsh或者Powershell时需要指定 Administrative权限,可通过右键菜单Run as Administrator实现。
( j5 B" Z2 B& | u然后会出现UAC,Allow即可~
7 A3 d: y9 u2 H3 f0 e* E$ O由于UAC权限具有继承性,即一个具有Administrative权限的Process启动的Process默认是具有Administrative权限的(除非显式的禁止继承)~
: i8 N, h2 U9 m, ]9 C. f因此可以通过启动一个有Administrative的Cmd或者Powershell的Shell来让脚本具有Administrative权限~
5 t* k8 q* n5 B" k- N; Z
0 S8 `0 ?- |, g8 Q4 m% e! t该方法仅在Win7下测试通过~WinXP下不通过~, X# I( C- A* X7 d2 X/ j
似乎原因是由于WinXP的WMI Class不支持Enable和Disable方法造成的~具体解决方案未知。 |
|