 鲜花( 3)  鸡蛋( 1)
|
方法一:NetSH大法~0 g: f2 a! P# ?% E
采用下列Netsh脚本8 x' { w+ A& I/ \ ?
interface
; q( U+ P Q2 B, I: n4 J P% P: iset interface name="Local Area Connection" admin=ENABLED/DISABLED8 B1 l3 J) ^: [6 v
, t; t0 @5 z# J0 L9 v4 G
方法二:Powershell+WMI大法! N( V$ S, \" s0 X _
$adapter = get-wmiobject Win32_NetworkAdapter -filter "NetConnectionID='Local Area Connection'"
, i# ^7 ?" J/ X9 H0 }, \$adapter.Disable()5 o/ J' n4 j/ n9 u# M
; j' m+ L C& b9 b" X3 w$ T3 ?同理可以VBS+WMI大法~' r- N6 ^* x4 C7 g. Z
这个就不说了~没啥意义了~+ r/ s/ | r ]) J: ^& P
! P% K9 P, b! ]
其中有一个非常重要的问题就是权限控制问题!
/ V: p1 z+ n% A; \# M3 tWindows 7的UAC很严格,不能像WinXP里那样随意修改系统设置而不通知用户。- ?0 e2 Z9 V+ Q, }% R/ n" P6 f) B( V
如果不赋予脚本执行环境以Administrative权限的话,脚本会执行失败,WMI返回码为05,Netsh报错:“An interface with this name is not registered with the router.”2 ?* A9 {6 |/ \
因此在启动Netsh或者Powershell时需要指定 Administrative权限,可通过右键菜单Run as Administrator实现。9 w! f0 M n" x% ~
然后会出现UAC,Allow即可~
0 Z8 g9 N2 }; Y, u由于UAC权限具有继承性,即一个具有Administrative权限的Process启动的Process默认是具有Administrative权限的(除非显式的禁止继承)~8 q0 x3 p/ Z5 `* Z. i# b# I
因此可以通过启动一个有Administrative的Cmd或者Powershell的Shell来让脚本具有Administrative权限~& p9 R7 c: C; s8 V4 M
5 A/ j& I0 ~% ^/ G' \; f该方法仅在Win7下测试通过~WinXP下不通过~
2 C3 T2 N+ j8 z3 i: ^ R' I7 q似乎原因是由于WinXP的WMI Class不支持Enable和Disable方法造成的~具体解决方案未知。 |
|