【转】VBS脚本 实现"无线网络连接"与"本地连接"的网卡禁用启用完美切换(优化版)
2010-11-16 19:34
926 查看
原来的文章被删了,不得不自己转载到blog里~
==============================
VBS脚本 实现"无线网络连接"与"本地连接"的网卡禁用启用完美切换(优化版)
在前一篇日志中,我写了《bat批处理+VBS 实现"无线网络连接"与"本地连接"的网卡禁用启用完美切换 》在那,我用到了bat和vbs结合。
今天我会将bat的代码直接移植至vbs,直接运行vbs即可。
本来是可以只用一个vbs的,但是只用一个vbs的话,每次都要用户选择是启用本地连接还是无线连接,感觉有点麻烦。
故将启用本地连接和启用无线连接分别放在不同vbs脚本中,用胡根据需要运行其中一个脚本即可。
******** 以下是"启用 Wireless.vbs"的代码(我只是分割线 不包括我)********
'-----------------启动无线网络相关服务-----------------
Set vbs=CreateObject("Wscript.Shell")
'***************Wireless Zero Configuration
vbs.Run "sc config WZCSVC start= demand"
vbs.Run "sc start WZCSVC"
'***************Atheros 配置服务
vbs.Run "sc config ACS start= demand"
vbs.Run "sc start ACS"
wscript.sleep 1000
sEnableConnectionName = "无线网络连接"
sDisableConnectionName = "本地连接"
Const ssfCONTROLS = 3
sEnableVerb = "启用(&A)"
sDisableVerb = "停用(&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(sDisableConnectionName) then
set oLanConnection = folderitem: exit for
end if
next
if oLanConnection is nothing then
msgbox "未找到 '" & sDisableConnectionName & "' item"
Else
Set oEnableVerb = nothing
set oDisableVerb = nothing
For each verb in oLanConnection.verbs
if verb.name = sDisableVerb then
set oDisableVerb = verb
Exit For
end if
next
If not (oDisableVerb is nothing) then
oDisableVerb.DoIt
end if
end If
'-----------------启用连接-----------------
set oLanConnection = nothing
for each folderitem in oNetConnections.items
if lcase(folderitem.name) = lcase(sEnableConnectionName) then
set oLanConnection = folderitem: exit for
end if
next
if oLanConnection is nothing then
msgbox "未找到 '" & sEnableConnectionName & "' item"
Else
Set oEnableVerb = nothing
set oDisableVerb = nothing
For each verb in oLanConnection.verbs
If verb.name = sEnableVerb then
set oEnableVerb = verb
Exit For
End if
next
If not (oEnableVerb is nothing) then
oEnableVerb.DoIt
end if
end If
wscript.sleep 1000
******** 以下是"启用 本地连接.vbs"的代码(我只是分割线 不包括我)********
sEnableConnectionName = "本地连接"
sDisableConnectionName = "无线网络连接"
Const ssfCONTROLS = 3
sEnableVerb = "启用(&A)"
sDisableVerb = "停用(&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(sDisableConnectionName) then
set oLanConnection = folderitem: exit for
end if
next
if oLanConnection is nothing then
msgbox "未找到 '" & sDisableConnectionName & "' item"
Else
Set oEnableVerb = nothing
set oDisableVerb = nothing
For each verb in oLanConnection.verbs
if verb.name = sDisableVerb then
set oDisableVerb = verb
Exit For
end if
next
If not (oDisableVerb is nothing) then
oDisableVerb.DoIt
end if
end If
'-----------------启用连接-----------------
set oLanConnection = nothing
for each folderitem in oNetConnections.items
if lcase(folderitem.name) = lcase(sEnableConnectionName) then
set oLanConnection = folderitem: exit for
end if
next
if oLanConnection is nothing then
msgbox "未找到 '" & sEnableConnectionName & "' item"
Else
Set oEnableVerb = nothing
set oDisableVerb = nothing
For each verb in oLanConnection.verbs
If verb.name = sEnableVerb then
set oEnableVerb = verb
Exit For
End if
next
If not (oEnableVerb is nothing) then
oEnableVerb.DoIt
end if
end If
wscript.sleep 800
'-----------------停止无线网络相关服务-----------------
Set vbs=CreateObject("Wscript.Shell")
'***************Wireless Zero Configuration
vbs.Run "sc stop WZCSVC"
vbs.Run "sc config WZCSVC start= disabled"
'***************Atheros 配置服务
vbs.Run "sc stop ACS"
vbs.Run "sc config ACS start= disabled"
相关文章推荐
- 用vbs实现本地连接禁用/启用脚本代码
- 如何将自己的"本地连接"网络或者"无线网络"分享
- C#实现启用与禁用本地网络的方式小结【3种方式】
- C#实现启用或停用本地网络连接
- Win7下建立WiFi热点共享网络(共享3G无线网卡/有线本地连接)
- 启用/禁用网卡网络连接 (C# 2005)
- 本地连接禁用/启用脚本
- 命令行启用/禁用网卡或网络连接
- C#实现启用、禁用本地网络的三种方式
- C#实现启用、禁用本地网络的三种方式
- Delphi实现WINDOWS“本地连接”的启用和禁用
- "网络适配器本地连接没有有效ip地址配置"错误的解决办法
- win7禁用启用本地连接bat及vbs
- 用Delphi实现WINDOWS XP中“本地连接”的启用和禁用
- 如何用Delphi实现WINDOWS XP中“本地连接”的启用和禁用 ?
- 启动/禁用本地连接的vbs脚本
- 无线网卡与本地连接不能同时使用&一机多网络的优先级设置
- 安装无线网卡后,显示"网络电缆被拔出"?
- C#实现启用、禁用本地网络的三种方式
- 用代码实现"停用/启用"网络连接