vb 如何检测当前是否接入互联网??

chenlishu413 2006-04-20 10:26:08
请高手赐教
...全文
105 3 点赞 打赏 收藏 举报
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Snoworld 2006-04-24
'以下是模塊中的內容
Option Explicit
'有关的API声明和定义'
Public Declare Function RasEnumConnections Lib "RasApi32.dll" Alias "RasEnumConnectionsA" (lpRasCon As Any, lpcb As Long, lpcConnections As Long) As Long

Public Declare Function RasGetConnectStatus Lib "RasApi32.dll" Alias "RasGetConnectStatusA" (ByVal hRasCon As Long, lpStatus As Any) As Long

'常数和变量的设定'
Public Const RAS95_MaxEntryName = 256
Public Const RAS95_MaxDeviceType = 16
Public Const RAS95_MaxDeviceName = 32
Public 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
Public Type RASCONNSTATUS95
dwSize As Long
RasConnState As Long
dwError As Long
szDeviceType(RAS95_MaxDeviceType) As Byte
szDeviceName(RAS95_MaxDeviceName) As Byte
End Type

'函数IsConnected返回连通的状态,如果为True则表示已连通'
Public Function IsConnected() As Boolean
Dim TRasCon(255) As RASCONN95
Dim lg As Long
Dim lpcon As Long
Dim RetVal As Long
Dim 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

'----------------------------------------------
Private Sub Form_Load()
If IsConnected = True Then
MsgBox ("您已经连通了Internet!")
End If
If IsConnected = False Then
MsgBox ("您还没有连通 Internet!")
End If
End Sub

  • 打赏
  • 举报
回复
amolucky 2006-04-24
看完http://www.itcnw.com/Article/Net/vb/200511/100024.html后 你应该会了
  • 打赏
  • 举报
回复
hot1kang1 2006-04-20
用winsock 连接 www.163.com :80 看是否连通

wskInternet.RemoteHost = "www.163.com "
wskInternet.RemotePort = "80"
wskInternet.Connect
Do
DoEvents
Loop Until wskInternet.State = sckConnected Or wskInternet.State = sckError If wskInternet.State = sckError Then
CheckInternet = False
Else
CheckInternet = True
End If

wskInternet.Close
  • 打赏
  • 举报
回复
相关推荐
发帖
VB基础类
加入

7548

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2006-04-20 10:26
社区公告
暂无公告