eeee0704 发表于 2008-6-13 19:16:33

如何将这段禁用网卡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 编辑 ]

sanhen 发表于 2008-6-13 19:50:48

照葫芦画瓢。大概看了一下。其实代码还可以精简的。有兴趣的朋友不妨修改一下。


;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

eeee0704 发表于 2008-7-30 19:28:08

呵呵,感谢了~~~

ygzxw 发表于 2009-5-20 12:29:25

好用!!谢谢!!

neity 发表于 2009-12-4 17:11:41

谢谢了,lz

UID 发表于 2009-12-25 16:07:42

非常好,找了很久了

lubb 发表于 2010-1-30 15:48:43

太好啦,顶起来。。

jonyzhr 发表于 2010-10-29 15:58:59

关于这方面的找了好久了.谢谢

zyj001991 发表于 2011-1-28 23:01:00

很强,横棒,横好

学习一下 发表于 2011-6-10 05:22:13

回复 2# sanhen


    这个超好,BLOG更超好,谢谢

ganyuansi 发表于 2011-12-6 19:14:35

{:face (382):},太长了 可惜新手看不懂

80ren 发表于 2011-12-9 14:28:22

新手看不懂

xiaolong100 发表于 2012-2-15 13:08:53

学习了,谢谢分享!

zhang_chg 发表于 2012-2-27 16:28:00

学习了,谢谢分享

gjianchang 发表于 2012-5-17 11:55:13

本帖最后由 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
查看完整版本: 如何将这段禁用网卡vbs转换成au3