中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-08-10 02:48
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 求一个切换网卡的脚本 查看 743 回复 2
楼 主 求一个切换网卡的脚本 发表于 2008-10-13 13:10 ·  中国 河南 三门峡 灵宝市 电信
初级用户
积分 34
发帖 13
注册 2007-03-02 07:38
19年会员
UID 80541
性别 男
状态 离线
我有两块网卡,在网络连接里显示为“本地连接1”和“本地连接2“,平时只启用一个,现在想用一个脚本,实现以下功能:判断现在启用的是哪一个网卡,把它停用,并且启用另外一个,然后作出提示。BAT或VBS均可。恳请高手赐教!
2 发表于 2008-10-13 16:36 ·  中国 广东 东莞 电信
初级用户
积分 98
发帖 45
注册 2008-08-30 01:29
17年会员
UID 124535
性别 男
状态 离线
手动禁止一个不就行了
3 发表于 2008-10-13 18:17 ·  中国 福建 漳州 联通
中级用户
★★
积分 228
发帖 125
注册 2008-08-25 19:17
17年会员
UID 124135
性别 男
状态 离线
这有一个VBS批处理文件,会停用一个网卡,然后启用一个网卡,你可以用这个
里面前两行定义网络的名称,前一个sEnableConnectionName是要启用的网络名,第二行那个是停用的网络名称,这个可以从控制面板-网络连接里面看到;
你只要将这个下面的内容复制下来,在记事本中粘贴出来,保存为VBS文件(如:切换网卡.vbs),就可以执行了

下面是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
论坛跳转: