vb怎样查看网络连接状态?
怎样判断是否有网线接入?就是右下角的网络连接图标,显示网络电缆没有插好,或者正常。因为我的是直接连接其他设备,winsock.state一直都是等于1的,所以这里没有办法...
怎样判断是否有网线接入?
就是右下角的网络连接图标,显示网络电缆没有插好,或者正常。
因为我的是直接连接其他设备,winsock.state一直都是等于1的,所以这里没有办法直接判断,还有什么其他方法吗? 展开
就是右下角的网络连接图标,显示网络电缆没有插好,或者正常。
因为我的是直接连接其他设备,winsock.state一直都是等于1的,所以这里没有办法直接判断,还有什么其他方法吗? 展开
1个回答
展开全部
Winsock.state 是显示当前Winsock 和另一主机连接的状态,它不是显示主机网络信息的.
用InternetGetConnectedState() 函数可以实现.为了方便你调用下面给模快代码你吧..
Private Declare Function InternetGetConnectedState Lib "Wininet.dll" (ByVal Flag As Long, ByVal Reserved As Long) As Long
Public Type Rtn_InetStat
IsConnecting As Boolean
IsModenConnecting As Boolean
IsModenBusy As Boolean
IsLANConnecting As Boolean
IsProxyConnecting As Boolean
End Type
Public Function RtnInetStat() As Rtn_InetStat
RtnInetStat.IsConnecting = RtnNunBooleanA(InternetGetConnectedState(0, 0))
RtnInetStat.IsModenConnecting = RtnNunBooleanB(InternetGetConnectedState(1, 0))
RtnInetStat.IsLANConnecting = RtnNunBooleanB(InternetGetConnectedState(2, 0))
RtnInetStat.IsProxyConnecting = RtnNunBooleanA(InternetGetConnectedState(4, 0))
RtnInetStat.IsModenBusy = RtnNunBooleanA(InternetGetConnectedState(8, 0))
End Function
Private Function RtnNunBooleanA(ByVal Num As Long) As Boolean
If Num = 0 Then
RtnNunBooleanA = False
Else
RtnNunBooleanA = True
End If
End Function
Private Function RtnNunBooleanB(ByVal Num As Long) As Boolean
If Num = 0 Then
RtnNunBooleanB = True
Else
RtnNunBooleanB = False
End If
End Function
获取当前网络是否已连接上:
Msgbox RtnInetStat.IsConnecting
用InternetGetConnectedState() 函数可以实现.为了方便你调用下面给模快代码你吧..
Private Declare Function InternetGetConnectedState Lib "Wininet.dll" (ByVal Flag As Long, ByVal Reserved As Long) As Long
Public Type Rtn_InetStat
IsConnecting As Boolean
IsModenConnecting As Boolean
IsModenBusy As Boolean
IsLANConnecting As Boolean
IsProxyConnecting As Boolean
End Type
Public Function RtnInetStat() As Rtn_InetStat
RtnInetStat.IsConnecting = RtnNunBooleanA(InternetGetConnectedState(0, 0))
RtnInetStat.IsModenConnecting = RtnNunBooleanB(InternetGetConnectedState(1, 0))
RtnInetStat.IsLANConnecting = RtnNunBooleanB(InternetGetConnectedState(2, 0))
RtnInetStat.IsProxyConnecting = RtnNunBooleanA(InternetGetConnectedState(4, 0))
RtnInetStat.IsModenBusy = RtnNunBooleanA(InternetGetConnectedState(8, 0))
End Function
Private Function RtnNunBooleanA(ByVal Num As Long) As Boolean
If Num = 0 Then
RtnNunBooleanA = False
Else
RtnNunBooleanA = True
End If
End Function
Private Function RtnNunBooleanB(ByVal Num As Long) As Boolean
If Num = 0 Then
RtnNunBooleanB = True
Else
RtnNunBooleanB = False
End If
End Function
获取当前网络是否已连接上:
Msgbox RtnInetStat.IsConnecting
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询