VB判断网络连接 30
在做一个小程序,要求判断网络是否连接正常。无论是拨号或者是LAN只类,只要连上了互连网就可以。返回一个TRUE,否则……以前找到过这个代码,现在找不到了。分不多,大哥门就...
在做一个小程序,要求判断网络是否连接正常。
无论是拨号或者是LAN只类,只要连上了互连网就可以。
返回一个TRUE,否则……
以前找到过这个代码,现在找不到了。
分不多,大哥门就帮帮忙!
不对,我把PPPOE的连接(就是ADSL宽带连接)断开,Online()返回的仍然是True....
不是我要的结果…… 展开
无论是拨号或者是LAN只类,只要连上了互连网就可以。
返回一个TRUE,否则……
以前找到过这个代码,现在找不到了。
分不多,大哥门就帮帮忙!
不对,我把PPPOE的连接(就是ADSL宽带连接)断开,Online()返回的仍然是True....
不是我要的结果…… 展开
2个回答
展开全部
Private Declare Function RasEnumConnections Lib "RasApi32.dll" Alias "RasEnumConnectionsA" (lpRasCon As Any, lpcb As Long, lpcConnections As Long) As Long
Private Declare Function RasGetConnectStatus Lib "RasApi32.dll" Alias "RasGetConnectStatusA" (ByVal hRasCon As Long, lpStatus As Any) As Long
Private Const RAS95_MaxEntryName = 256
Private Const RAS95_MaxDeviceType = 16
Private Const RAS95_MaxDeviceName = 32
Private Type RASCONN95
dwSize As Long
hRasCon As Long
szEntryName(RAS95_MaxEntryName) As Byte
szDeviceType(RAS95_MaxDeviceType) As Byte
szDeviceName(RAS95_MaxDeviceName) As Byte
End Type
Private Type RASCONNSTATUS95
dwSize As Long
RasConnState As Long
dwError As Long
szDeviceType(RAS95_MaxDeviceType) As Byte
szDeviceName(RAS95_MaxDeviceName) As Byte
End Type
Public Function IsConnected() As Boolean '函数IsConnected返回连通的状态,如果为True则表示已连通
Dim TRasCon(255) As RASCONN95, lg As Long, lpcon As Long, RetVal As Long, Tstatus As RASCONNSTATUS95
TRasCon(0).dwSize = 412
lg = 256 * TRasCon(0).dwSize
RetVal = RasEnumConnections(TRasCon(0), lg, lpcon)
If RetVal <> 0 Then
MsgBox "错误"
Exit Function
End If
Tstatus.dwSize = 160
RetVal = RasGetConnectStatus(TRasCon(0).hRasCon, Tstatus)
If Tstatus.RasConnState = &H2000 Then
IsConnected = True
Else
IsConnected = False
End If
End Function
用 IsConnected()
Private Declare Function RasGetConnectStatus Lib "RasApi32.dll" Alias "RasGetConnectStatusA" (ByVal hRasCon As Long, lpStatus As Any) As Long
Private Const RAS95_MaxEntryName = 256
Private Const RAS95_MaxDeviceType = 16
Private Const RAS95_MaxDeviceName = 32
Private Type RASCONN95
dwSize As Long
hRasCon As Long
szEntryName(RAS95_MaxEntryName) As Byte
szDeviceType(RAS95_MaxDeviceType) As Byte
szDeviceName(RAS95_MaxDeviceName) As Byte
End Type
Private Type RASCONNSTATUS95
dwSize As Long
RasConnState As Long
dwError As Long
szDeviceType(RAS95_MaxDeviceType) As Byte
szDeviceName(RAS95_MaxDeviceName) As Byte
End Type
Public Function IsConnected() As Boolean '函数IsConnected返回连通的状态,如果为True则表示已连通
Dim TRasCon(255) As RASCONN95, lg As Long, lpcon As Long, RetVal As Long, Tstatus As RASCONNSTATUS95
TRasCon(0).dwSize = 412
lg = 256 * TRasCon(0).dwSize
RetVal = RasEnumConnections(TRasCon(0), lg, lpcon)
If RetVal <> 0 Then
MsgBox "错误"
Exit Function
End If
Tstatus.dwSize = 160
RetVal = RasGetConnectStatus(TRasCon(0).hRasCon, Tstatus)
If Tstatus.RasConnState = &H2000 Then
IsConnected = True
Else
IsConnected = False
End If
End Function
用 IsConnected()
参考资料: 网络
展开全部
Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef dwFlags As Long, ByVal dwReserved As Long) As Long
Private Sub Form_Load()
If InternetGetConnectedState(0&, 0&) Then
MsgBox "网络已连接"
Else
MsgBox "当前没有联网"
End If
End Sub
Private Sub Form_Load()
If InternetGetConnectedState(0&, 0&) Then
MsgBox "网络已连接"
Else
MsgBox "当前没有联网"
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询