bat批处理+VBS 实现无线网络连接与本地连接的网卡禁用启用切换bat批处理+VBS 实现无线网络连接与本地连接的网卡禁用启用切换
bat批处理+VBS 实现"无线网络连接"与"本地连接"的网卡禁用启用完美切换 【前言】
本人上网主要是两种方式,一个是直接插网线拨号的宽带,一个是无线网络。
因为在不同时间不同地点各有所需,所以经常停用一个,再启用另一个,很麻烦。
于是便想到用批处理来实现,但具体实现过程中发现光批处理还不够,主要还得用到VBS脚本。
【文件】
实现所需功能共需编写四个文件
1、Run-WirelessConnection.vbs
----启用无线连接 同时禁...
bat批处理+VBS 实现无线网络连接与本地连接的网卡禁用启用切换
bat批处理+VBS 实现"无线网络连接"与"本地连接"的网卡禁用启用完美切换 【前言】
本人上网主要是两种方式,一个是直接插网线拨号的宽带,一个是无线网络。
因为在不同时间不同地点各有所需,所以经常停用一个,再启用另一个,很麻烦。
于是便想到用批处理来实现,但具体实现过程中发现光批处理还不够,主要还得用到VBS脚本。
【文件】
实现所需功能共需编写四个文件
1、Run-WirelessConnection.vbs
----启用无线连接 同时禁用本地连接 的VBS脚本
2、Run-LocalConnection.vbs
----启用本地连接 同时禁用无线连接 的VBS脚本
3、启用 Wireless.bat
----启用无线网的相关服务 同时调用Run-WirelessConnection.vbs
4、启用 本地连接.bat
----关闭无线网的相关服务 同时调用Run-LocalConnection.vbs
说明:将这四个文件放在同一个文件夹中 用户只要运行 “启用 Wireless.bat” 或“启用 本地连接.bat” 即可实现网络连接的快速切换。
在这里,我将无线网卡相关的服务(一搬是Wireless Zero Configuration和Atheros 配置服务)也设置为手动启动和关闭,并在bat文件中进行启动和关闭操作。目的就是取消无线网路的自动启动。当然,若读者希望这些服务自动启动,那么3和4这两个bat文件根本就不需要了,用户可直接运行1和2连个vbs文件即可实现切换。
【代码】
********以下是"Run-WirelessConnection.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
********以下是"Run-LocalConnection.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
********以下是"启用 Wireless.bat"的代码(我只是分割线 不包括我)******** @echo off
rem ***************Wireless Zero Configuration @echo.
sc config WZCSVC start= demand
@echo.
sc start "WZCSVC"
rem ***************Atheros 配置服务
@echo.
sc config ACS start= demand
@echo.
sc start "ACS"
start Run-WirelessConnection.vbs
********以下是"启用 本地连接.bat"的代码(我只是分割线 不包括我)******** @echo off
start Run-LocalConnection.vbs
rem ***************Wireless Zero Configuration @echo.
sc config WZCSVC start= disabled @echo.
sc stop "WZCSVC"
rem ***************Atheros 配置服务
@echo.
sc config ACS start= disabled @echo.
sc stop "ACS"
本文档为【bat批处理+VBS 实现无线网络连接与本地连接的网卡禁用启用切换】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。