如何将这段禁用网卡vbs转换成au3
vbs代码如下:Const ssfCONTROLS = 3
sConnectionName = "本地连接"'可改成需要控制的连接名称,如"无线网络连接"等
sEnableVerb = "启用(&A)"
sDisableVerb = "停用(&B)" 'XP系统中应为 "停用(&B)"
set shellApp = createobject("shell.application")
set oControlPanel = shellApp.Namespace(ssfCONTROLS)
set oNetConnections = nothing
for each folderitem in oControlPanel.items
if folderitem.name= "网络连接" then
set oNetConnections = folderitem.getfolder: exit for
end if
next
if oNetConnections is nothing then
msgbox "未找到网络连接文件夹"
wscript.quit
end if
set oLanConnection = nothing
for each folderitem in oNetConnections.items
if lcase(folderitem.name)= lcase(sConnectionName) then
set oLanConnection = folderitem: exit for
end if
next
if oLanConnection is nothing then
msgbox "未找到 '" & sConnectionName & "' item"
wscript.quit
end if
bEnabled = true
set oEnableVerb = nothing
set oDisableVerb = nothing
s = "Verbs: " & vbcrlf
for each verb in oLanConnection.verbs
s = s & vbcrlf & verb.name
if verb.name = sEnableVerb then
set oEnableVerb = verb
bEnabled = false
end if
if verb.name = sDisableVerb then
set oDisableVerb = verb
end if
next
'debugging displays left just in case...
'
'msgbox s ': wscript.quit
'msgbox "Enabled: " & bEnabled ': wscript.quit
'not sure why, but invokeverb always seemed to work
'for enable but not disable.
'
'saving a reference to the appropriate verb object
'and calling the DoIt method always seems to work.
'
if bEnabled then
'oLanConnection.invokeverb sDisableVerb
oDisableVerb.DoIt
else
'oLanConnection.invokeverb sEnableVerb
oEnableVerb.DoIt
end if
'adjust the sleep duration below as needed...
'
'if you let the oLanConnection go out of scope
'and be destroyed too soon, the action of the verb
'may not take...
'
wscript.sleep 400
如题,我就只想知道禁用启用网卡的实现方式,请高手指定
[ 本帖最后由 eeee0704 于 2008-7-30 19:26 编辑 ] 照葫芦画瓢。大概看了一下。其实代码还可以精简的。有兴趣的朋友不妨修改一下。
;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 平台下测试成功。
后续更新会写在BLOG。
http://www.lunhui.net.cn/article.asp?id=20 呵呵,感谢了~~~ 好用!!谢谢!! 谢谢了,lz 非常好,找了很久了 太好啦,顶起来。。 关于这方面的找了好久了.谢谢 很强,横棒,横好 回复 2# sanhen
这个超好,BLOG更超好,谢谢 {:face (382):},太长了 可惜新手看不懂 新手看不懂 学习了,谢谢分享! 学习了,谢谢分享 本帖最后由 gjianchang 于 2012-5-17 12:35 编辑
;WIN7下直接用这个脚本就行了:
#include <Process.au3>
$author = "Made by gjianchang"
$objwmiservice = ObjGet('winmgmts:\\localhost\root\CIMV2')
$colitems = $objWMIService.ExecQuery ('SELECT * FROM Win32_NetworkAdapter','WQL', 0x10 + 0x20)
If IsObj($colitems) Then
For $objitem In $colitems
If $objitem.netconnectionid <> '' Then
local $enable = $objitem.NetEnabled
Select
case $enable = True
$objitem.disable
ToolTip("正在禁用 "& '"'&$objitem.netconnectionid&'"'&@CR&"请等待...", 700, 400)
sleep (5000)
$objitem.enable
ToolTip("正在启用 "& '"'&$objitem.netconnectionid&'"'&@CR&"请等待...", 700, 400)
sleep (5000)
case $enable = False
EndSelect
EndIf
Next
EndIf
页:
[1]
2