0 out of 1 rated this helpful - Rate this topic

InternetCheckConnection function

Applies to: desktop apps only

Allows an application to check if a connection to the Internet can be established.

Syntax

BOOL InternetCheckConnection(
  __in  LPCTSTR lpszUrl,
  __in  DWORD dwFlags,
  __in  DWORD dwReserved
);

Parameters

lpszUrl [in]

Pointer to a null-terminated string that specifies the URL to use to check the connection. This value can be NULL.

dwFlags [in]

Options. FLAG_ICC_FORCE_CONNECTION is the only flag that is currently available. If this flag is set, it forces a connection. A sockets connection is attempted in the following order:

  • If lpszUrl is non-NULL, the host value is extracted from it and used to ping that specific host.
  • If lpszUrl is NULL and there is an entry in the internal server database for the nearest server, the host value is extracted from the entry and used to ping that server.
dwReserved [in]

This parameter is reserved and must be 0.

Return value

Returns TRUE if a connection is made successfully, or FALSE otherwise. Use GetLastError to retrieve the error code. ERROR_NOT_CONNECTED is returned by GetLastError if a connection cannot be made or if the sockets database is unconditionally offline.

Remarks

Note  WinINet does not support server implementations. In addition, it should not be used from a service. For server implementations or services use Microsoft Windows HTTP Services (WinHTTP).

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Wininet.h

Library

Wininet.lib

DLL

Wininet.dll

Unicode and ANSI names

InternetCheckConnectionW (Unicode) and InternetCheckConnectionA (ANSI)

See also

Enabling Internet Functionality
WinINet Functions

 

 

Send comments about this topic to Microsoft

Build date: 2/7/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
How I used this code
'Will check to see if user is online, if not close program
    Public Declare Function InternetGetConnectedStateEx Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal lpszConnectionName As String, ByVal dwNameLen As Integer, ByVal dwReserved As Long) As Long

    Public Function CheckInternetConnection() As Boolean

        Dim aux As String = Nothing

        Dim r As Long = Nothing

        r = InternetGetConnectedStateEx(Nothing, aux, 254, 0)

        If r = 1 Then

            CheckInternetConnection = True

        Else

            CheckInternetConnection = False
            MessageBox.Show("You must be online to access this content")
        End If
        Return CheckInternetConnection
    End Function