elexy 发表于 2009-3-11 13:23:38

讨论一段禁用/启用网络连接的代码

;AU3版本禁用/启用网卡
; www.autoitx.com 中文论坛版权所有
Global Const $ssfCONTROLS = 3
$sConnectionName = "本地连接"
$sEnableVerb = "启用(&A)"
$sDisableVerb = "停用(&B)"   ;2003 应改为“禁用(&B)”
$shellApp = ObjCreate("shell.application")
$oControlPanel = $shellApp.Namespace($ssfCONTROLS)
$oNetConnections = ""
for $folderitem in $oControlPanel.items   
if $folderitem.name = "网络连接" then   
    $oNetConnections = $folderitem.getfolder
ExitLoop
   endif
next
if $oNetConnections ="" then
MsgBox(0,"","未找到网络连接文档夹")
   Exit
endif
$oLanConnection = ""
for $folderitem in $oNetConnections.items   
if StringLower($folderitem.name) = StringLower($sConnectionName) then
       $oLanConnection = $folderitem
ExitLoop   
endif
next
if $oLanConnection ="" then
   Exit
endif
$bEnabled = true
$oEnableVerb = ""
$oDisableVerb = ""
$s = "Verbs: " & @crlf
for $verb in $oLanConnection.verbs
   $s = $s & @crlf & $verb.name   
if $verb.name = $sEnableVerb then      
   $oEnableVerb = $verb      
$bEnabled = false   
endif   
if $verb.name = $sDisableVerb then   
    $oDisableVerb = $verb
   endif
next
if $bEnabled then   
$oDisableVerb.DoIt
else   
$oEnableVerb.DoIt
endif
sleep(1000)

以上为论坛一位大侠做的,我的测试平台为 XP SP3 在公司局域网中。发现在在网络连接已经启用的情况下,运行后可以禁用,但是脚本就结束了,没有启用~。此时机器网络连接是禁用状态,再运行一次,就启用了。请问如何解决???

elexy 发表于 2009-3-11 22:05:31

顶上去求解!!!!!!!!

sanhen 发表于 2009-3-11 23:57:38

这个脚本本来就是如此的。要想合适自己用的,必须更改。

xayle 发表于 2009-3-12 08:21:31

这个用devcon 更快
页: [1]
查看完整版本: 讨论一段禁用/启用网络连接的代码