Vb6 在windows 8中检查internet连接时出错

Vb6 在windows 8中检查internet连接时出错,vb6,icmp,Vb6,Icmp,我有一个vb6代码,用于测试电脑是否有internet连接。我利用检查google DNS来检查它。它在Windows XP中运行良好。但在Windows 8中,如果internet连接或未连接,它总是返回成功(internet已连接)。 我在利用 下面是编码的一部分 Private Function CheckForInternet(ByVal ServerIP As String, ByRef IsTimedOut As Boolean) A s Boolean On Error GoTo

我有一个vb6代码,用于测试电脑是否有internet连接。我利用检查google DNS来检查它。它在Windows XP中运行良好。但在Windows 8中,如果internet连接或未连接,它总是返回成功(internet已连接)。 我在利用 下面是编码的一部分

Private Function CheckForInternet(ByVal ServerIP As String, ByRef IsTimedOut As Boolean) A

s Boolean
On Error GoTo CheckForInternet_EH

Dim Reply As ICMP_ECHO_REPLY
Dim lngSuccess As Long
Dim strIPAddress As String
Dim a As String
Dim startTimer As Single
Dim EndTimer As Single
Const Time_out_in_ms As Integer = 1000
'Get the sockets ready.
If SocketsInitialize() Then
    'Address to ping
    strIPAddress = ServerIP

    'Ping the IP that is passing the address and get a reply.
    lngSuccess = ping(strIPAddress, Time_out_in_ms, Reply)

    'Clean up the sockets.
    SocketsCleanup

    ''Return Value
    If lngSuccess = ICMP_SUCCESS Then
        CheckForInternet = True
    ElseIf lngSuccess = ICMP_STATUS_REQUEST_TIMED_OUT Then
        IsTimedOut = True
    End If
'Else
'    'Winsock error failure, initializing the sockets.
'    Debug.Print WINSOCK_ERROR
End If

Exit Function
CheckForInternet_EH:
Call msglog(Err.Description & Space(10) & "CheckForInternet", False)
End Function
下面是ping过程

Public Function ping(ByVal sAddress As String, ByVal time_out As Long, Reply As ICMP_ECHO_REPLY) As Long
On Error GoTo ping_EH

Dim hIcmp As Long
Dim lAddress As Long
Dim lTimeOut As Long
Dim StringToSend As String

'Short string of data to send
StringToSend = "hello"

'ICMP (ping) timeout
lTimeOut = time_out ''ms

'Convert string address to a long representation.
lAddress = inet_addr(sAddress)

If (lAddress <> -1) And (lAddress <> 0) Then

    'Create the handle for ICMP requests.
    hIcmp = IcmpCreateFile()

    If hIcmp Then
        'Ping the destination IP address.
        Call IcmpSendEcho(hIcmp, lAddress, StringToSend, Len(StringToSend), 0, Reply, Len(Reply), lTimeOut)

        'Reply status
        ping = Reply.Status

        'Close the Icmp handle.
        IcmpCloseHandle hIcmp
    Else
        'Debug.Print "failure opening icmp handle."
        ping = -1
    End If
Else
    ping = -1
End If
Exit Function
ping_EH:
Call msglog(Err.Description & Space(10) & "ping", False)
End Function
提示:64位pc的链接IP_选项_信息不同等。。等 在链接中,它被称为“一个缓冲区,用于保存对echo请求的任何回复。返回时,缓冲区包含一个ICMP_echo_回复结构数组,后跟回复的选项和数据。缓冲区应足够大,以容纳至少一个ICMP_echo_回复结构加上RequestSize字节的数据。” 所以我现在想知道如何声明ICMP_ECHO_REPLY和IP_OPTION_信息32?(我只使用了ICMP_ECHO_REPLY和IP_OPTION_信息)
因此,请帮助我解决问题

要检查internet连接,我执行了以下两个简单功能:

Option Explicit
Private Declare Function InternetCheckConnectionA Lib "wininet.dll" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long

Private Const FLAG_ICC_FORCE_CONNECTION  As Long = &H1

Public Function IsInternetOn() As Boolean
    IsInternetOn = InternetCheckConnectionA("http://www.google.com/", FLAG_ICC_FORCE_CONNECTION, 0&)
End Function
第二条:

Option Explicit
Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long

Private Function IsInternetOn() As Boolean
   IsInternetOn = InternetGetConnectedState(0&, 0&)
End Function
呼叫示例:

Msgbox IsInternetOn()
Msgbox IsInternetOn()