注册 登录
编程论坛 VB6论坛

请问在win10中,怎么用vb控制网卡呢?下面是xp中控制网卡

mail98 发布于 2016-12-24 09:57, 1434 次点击
"网络连接" 文件夹在xp和win10中的位置不一样,win10中如果在oControlPanel.Items中找 网络连接 文件夹是找不到的,该怎么修改呢?谢谢!

Const ssfCONTROLS = 3
sConnectionName = "内" '可改成需要控制的连接名称,如"无线网络连接"等
sEnableVerb = "启用(&A)"
sDisableVerb = "停用(&B)" 'XP系统中应为 "停用(&B)"、 "禁用(&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
MsgBox folderitem.Name
Next
Exit Sub

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

If bEnabled  Then
' oLanConnection.invokeverb sDisableVerb

oDisableVerb.DoIt

Text43.Text = Text43.Text & Time() & vbCrLf
Label96.ForeColor = &HFF&
ElseIf bEnabled = False Then
' oLanConnection.invokeverb sEnableVerb
oEnableVerb.DoIt

End If
2 回复
#2
mail982016-12-24 13:57
用这个吧也不行,它需要 管理员模式的命令提示符,直接在用管理员模式的命令提示符是可以的,但在vb下怎么调用 管理员模式的命令提示符呢?
netsh interface set interface name="网络连接" admin=DISABLED
#3
wube2016-12-29 10:30
是要控制别人的网卡还是自己的?
虽然没做过~但是我会尝试使用WMI去实现这功能~
先找出控制网卡的类~再呼叫此类使用内部的方法去完成~
https://msdn.
找出VBS CODE再改写成VB6的CODE~
只有本站会员才能查看附件,请 登录

1