找回密码
 加入
搜索
查看: 15746|回复: 24

如何将这段禁用网卡vbs转换成au3

 火... [复制链接]
发表于 2008-6-13 19:16:33 | 显示全部楼层 |阅读模式
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 编辑 ]
发表于 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
 楼主| 发表于 2008-7-30 19:28:08 | 显示全部楼层
呵呵,感谢了~~~
发表于 2009-5-20 12:29:25 | 显示全部楼层
好用!!谢谢!!
发表于 2009-12-4 17:11:41 | 显示全部楼层
谢谢了,lz
发表于 2009-12-25 16:07:42 | 显示全部楼层
非常好,找了很久了
发表于 2010-1-30 15:48:43 | 显示全部楼层
太好啦,顶起来。。
发表于 2010-10-29 15:58:59 | 显示全部楼层
关于这方面的找了好久了.谢谢
发表于 2011-1-28 23:01:00 | 显示全部楼层
很强,横棒,横好
发表于 2011-6-10 05:22:13 | 显示全部楼层
回复 2# sanhen


    这个超好,BLOG更超好,谢谢
发表于 2011-12-6 19:14:35 | 显示全部楼层
,太长了 可惜新手看不懂
发表于 2011-12-9 14:28:22 | 显示全部楼层
新手看不懂
发表于 2012-2-15 13:08:53 | 显示全部楼层
学习了,谢谢分享!
发表于 2012-2-27 16:28:00 | 显示全部楼层
学习了,谢谢分享
发表于 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金钱 +10 收起 理由
tk390480 + 10

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-12 00:14 , Processed in 0.078096 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表