设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1305|回复: 4
打印 上一主题 下一主题

[Access本身] 这个网络检测要那几个组件啊?(版主进)

[复制链接]
跳转到指定楼层
1#
发表于 2008-3-24 09:50:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Private Function InternetConnected(Optional ByRef eConnectionInfo _
    As EIGCInternetConnectionState, Optional ByRef _
    sConnectionName As String) As Boolean
   
    Dim dwFlags As Long
    Dim sNameBuf As String
    Dim lR As Long
    Dim iPos As Long
   
    sNameBuf = String$(513, 0)
    lR = InternetGetConnectedStateEx(dwFlags, sNameBuf, 512, 0&)
    eConnectionInfo = dwFlags
    iPos = InStr(sNameBuf, vbNullChar)
    If iPos > 0 Then
        sConnectionName = Left$(sNameBuf, iPos - 1)
    ElseIf Not sNameBuf = String$(513, 0) Then
        sConnectionName = sNameBuf
    End If
    InternetConnected = (lR = 1)
End Function
Private Sub Command0_Click()
Dim Inet As Boolean
Dim eR As EIGCInternetConnectionState
Dim sName As String
    If Inet = False Then
        MsgBox "没有连接到Internet。"
        Exit Sub
    ElseIf Inet = True Then
        MsgBox "已经连接到Internet。"
        Exit Sub
    End If
End Sub
Private Sub Form_Load()
      Inet = InternetConnected(eR, sName)
  SocketsInitialize
End Sub

[ 本帖最后由 lixun005 于 2008-3-24 10:13 编辑 ]
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2008-3-24 10:21:06 | 只看该作者
你这个函数并不全呀 很多参数都没定义
3#
发表于 2008-3-24 10:26:51 | 只看该作者
检测是否已连接Internet 也可用下面的代码
Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Private Const INTERNET_FLAG_RELOAD = &H80000000
Private Const INTERNET_FLAG_KEEP_CONNECTION = &H400000
Private Const INTERNET_FLAG_NO_CACHE_WRITE = &H4000000

Private Declare Function InternetOpen _
Lib "wininet.dll" Alias "InternetOpenW" _
(ByVal lpszAgent As Long, _
ByVal dwAccessType As Long, _
ByVal lpszProxyName As Long, _
ByVal lpszProxyBypass As Long, _
ByVal dwFlags As Long) As Long

Private Declare Function InternetOpenUrl _
Lib "wininet.dll" Alias "InternetOpenUrlW" _
(ByVal hInet As Long, _
ByVal lpszUrl As Long, _
ByVal lpszHeaders As Long, _
ByVal dwHeadersLength As Long, _
ByVal dwFlags As Long, _
ByVal dwContext As Long) As Long

Private Declare Function InternetCloseHandle _
Lib "wininet.dll" (ByVal hInet As Long) As Long

Public Function TestConnection(stSite As String) As Boolean
    Dim hInet As Long
    Dim hUrl As Long
    Dim lFlags As Long
    Dim url As Variant
   
    hInet = InternetOpen(StrPtr(Dir(CurrentDb.Name)), INTERNET_OPEN_TYPE_PRECONFIG, 0&, 0&, 0&)
    If hInet Then
        lFlags = INTERNET_FLAG_KEEP_CONNECTION Or _
                    INTERNET_FLAG_NO_CACHE_WRITE Or _
                    INTERNET_FLAG_RELOAD
        hUrl = InternetOpenUrl(hInet, StrPtr(stSite), 0&, 0, lFlags, 0)
        If hUrl Then
            TestConnection = True
            Call InternetCloseHandle(hUrl)
            hUrl = 0
         End If
    End If
    Call InternetCloseHandle(hInet)
    hInet = 0
End Function

Private Sub Command0_Click()
MsgBox TestConnection("http://www.google.com")
End Sub
4#
 楼主| 发表于 2008-3-24 10:48:41 | 只看该作者
非常感谢,不过ping网站我这面没有合适的网站,公司屏蔽了好多网站[:47] ,google.com有时也打不开的,郁闷死了,不过还是谢谢你![:13]
5#
发表于 2008-3-24 10:50:12 | 只看该作者
学习[:50]
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-14 14:16 , Processed in 0.085803 second(s), 28 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表