vb中如何断开网络,如何重连

弱弱的问下,2楼的高手,给点解释可以吗那谢谢了,我明白原理了,谢谢... 弱弱的问下,2楼的高手,给点解释可以吗
那谢谢了,我明白原理了,谢谢
展开
 我来答
tzwsoho
推荐于2016-06-13 · TA获得超过130个赞
知道小有建树答主
回答量:119
采纳率:0%
帮助的人:105万
展开全部
Option Explicit

Private Const NO_ERROR As Long = 0

Private Const MAX_ADAPTER_NAME As Long = 256

Private Type IP_ADAPTER_INDEX_MAP
Index As Long
wsName As String * MAX_ADAPTER_NAME
End Type

Private Type IP_INTERFACE_INFO
NumAdapters As Long
Adapter(0) As IP_ADAPTER_INDEX_MAP
End Type

Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)

Private Declare Function IpReleaseAddress Lib "IPHLPAPI.dll" (ByRef AdapterInfo As IP_ADAPTER_INDEX_MAP) As Long
Private Declare Function IpRenewAddress Lib "IPHLPAPI.dll" (ByRef AdapterInfo As IP_ADAPTER_INDEX_MAP) As Long

Private Declare Function GetInterfaceInfo Lib "IPHLPAPI.dll" (ByRef pIfTable As Any, ByRef dwOutBufLen As Long) As Long

Private Sub Command1_Click()
Dim i As Long, lOut As Long, lNum As Long
Dim III As IP_INTERFACE_INFO, arrTmp() As Byte
Dim aIAIM() As IP_ADAPTER_INDEX_MAP, IAIM As IP_ADAPTER_INDEX_MAP
i = GetInterfaceInfo(III, lOut)
ReDim arrTmp(lOut - 1)
i = GetInterfaceInfo(arrTmp(0), lOut)
If i <> NO_ERROR Then Exit Sub
CopyMemory lNum, arrTmp(0), 4
Debug.Print lNum; " Network Interface(s) Total!!!"
ReDim aIAIM(lNum - 1)
For i = 0 To lNum - 1
CopyMemory aIAIM(i), arrTmp(4 + i * Len(IAIM)), Len(IAIM)
Debug.Print "Index:"; aIAIM(i).Index; " Name:"; StrConv(aIAIM(0).wsName, vbFromUnicode)
Next

Debug.Print IpReleaseAddress(aIAIM(0)) '断开第一个网卡
End Sub

Private Sub Command2_Click()
Dim i As Long, lOut As Long, lNum As Long
Dim III As IP_INTERFACE_INFO, arrTmp() As Byte
Dim aIAIM() As IP_ADAPTER_INDEX_MAP, IAIM As IP_ADAPTER_INDEX_MAP
i = GetInterfaceInfo(III, lOut)
ReDim arrTmp(lOut - 1)
i = GetInterfaceInfo(arrTmp(0), lOut)
If i <> NO_ERROR Then Exit Sub
CopyMemory lNum, arrTmp(0), 4
Debug.Print lNum; " Network Interface(s) Total!!!"
ReDim aIAIM(lNum - 1)
For i = 0 To lNum - 1
CopyMemory aIAIM(i), arrTmp(4 + i * Len(IAIM)), Len(IAIM)
Debug.Print "Index:"; aIAIM(i).Index; " Name:"; StrConv(aIAIM(0).wsName, vbFromUnicode)
Next

Debug.Print IpRenewAddress(aIAIM(0)) '恢复第一个网卡
End Sub

禁用/恢复指定网卡。。。

************************************************************

都是API的用法哈。。。。没什么好解释的 = =!抱歉。。。。
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
Coo_boi
2010-05-26 · TA获得超过1333个赞
知道大有可为答主
回答量:2209
采纳率:50%
帮助的人:250万
展开全部
have a try

shell "cmd.exe /c ipconfig /release",vbhide//close the network

shell "cmd.exe /c ipconfig /renew",vbhide//open ...
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式