以下代码禁用本地连接并启用无线连接,之前它运行良好。
最近我的带有64的Windows 7已更新,我发现代码不起作用,为什么?
顺便说一句,我想也许微软可能会更改NetConnectionID的名称,但我不确定。my.vbs
Set WMI=GetObject("winmgmts:\\.\root\cimv2")
Set w=WMI.ExecQuery("select * from WIN32_NetworkAdapter")
For Each i In w
If i.NetConnectionID="本地连接" Then
i.Disable()
End If
If i.NetConnectionID="无线网络连接" Then
i.Enable()
End If
next
WScript.Sleep 3000
CreateObject("WScript.Shell").run "netsh wlan connect name=weiiPhone6",0
修改后的代码
Dim retValue
Set WMI=GetObject("winmgmts:\\.\root\cimv2")
Set w=WMI.ExecQuery("select * from WIN32_NetworkAdapter")
For Each i In w
If i.NetConnectionID="本地连接" Then
retValue = i.Disable()
End If
If i.NetConnectionID="无线网络连接" Then
retValue = i.Enable()
End If
If retValue <> 0 Then
'Check return value for the specific error.
MSGBOX retValue
End If
retValue = 0
Next
WScript.Sleep 3000
CreateObject("WScript.Shell").run "netsh wlan connect name=weiiPhone6",0
答案 0 :(得分:1)
可能是因为没有使用提升的权限运行脚本。如果您确信正在运行If
语句,请尝试检查Enable()
和Disable()
方法的返回值。
Dim retValue
Set WMI=GetObject("winmgmts:\\.\root\cimv2")
Set w=WMI.ExecQuery("select * from WIN32_NetworkAdapter")
For Each i In w
If i.NetConnectionID="本地连接" Then
retValue = i.Disable()
End If
If i.NetConnectionID="无线网络连接" Then
retValue = i.Enable()
End If
If retValue <> 0 Then
'Check return value for the specific error.
End If
retValue = 0
Next
WScript.Sleep 3000
CreateObject("WScript.Shell").run "netsh wlan connect name=weiiPhone6",0