 鲜花( 3)  鸡蛋( 1)
|
方法一:NetSH大法~
- O4 h& d/ T, B: K/ _采用下列Netsh脚本6 {8 |" J% x2 w! r7 {
interface+ k3 n0 K2 m9 g/ h: Q
set interface name="Local Area Connection" admin=ENABLED/DISABLED( _' ~& Y5 o+ [! I
$ x. V4 P7 Z% H( c2 i
方法二:Powershell+WMI大法
1 [. f2 Q& J* u- ?$adapter = get-wmiobject Win32_NetworkAdapter -filter "NetConnectionID='Local Area Connection'"
, g0 ^1 m# L& f3 Q$adapter.Disable() q/ ^8 Q# W: I3 s( e8 T2 t5 `" e8 T
7 j$ Z& j! m0 \* Q" r5 J同理可以VBS+WMI大法~
2 T' g' e8 C( ]: E$ {) r' j' o这个就不说了~没啥意义了~
% d7 \; r2 @: w
, f$ ?: C/ e" k' @其中有一个非常重要的问题就是权限控制问题!' |/ _! f" t( v1 {3 e" ?5 c3 Q
Windows 7的UAC很严格,不能像WinXP里那样随意修改系统设置而不通知用户。6 m5 T1 ~- _ L# J1 }. z, y
如果不赋予脚本执行环境以Administrative权限的话,脚本会执行失败,WMI返回码为05,Netsh报错:“An interface with this name is not registered with the router.” F8 Q3 O, Y! l
因此在启动Netsh或者Powershell时需要指定 Administrative权限,可通过右键菜单Run as Administrator实现。
. Y8 p1 n" M( _8 t1 C) |3 K4 S然后会出现UAC,Allow即可~
; q$ I \+ z: T% H' `1 s3 Y, r由于UAC权限具有继承性,即一个具有Administrative权限的Process启动的Process默认是具有Administrative权限的(除非显式的禁止继承)~
8 p6 D9 n7 t6 _& k2 ~9 _6 D因此可以通过启动一个有Administrative的Cmd或者Powershell的Shell来让脚本具有Administrative权限~
8 ^) K8 D8 F. Q! ]! @
- j8 N* M4 n! K4 W2 `该方法仅在Win7下测试通过~WinXP下不通过~4 T# S. g9 Q" y( E) c; `/ f$ ~
似乎原因是由于WinXP的WMI Class不支持Enable和Disable方法造成的~具体解决方案未知。 |
|