Desktop Functions:

   Smart Device Functions:

Show Recent Changes
Subscribe (RSS)
Misc. Pages
Helpful Tools
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
InternetGetConnectedState (wininet)
TODO - a short description

C# Signature:

[DllImport("wininet.dll", SetLastError=true)]
extern static bool InternetGetConnectedState(out int lpdwFlags, int dwReserved);

enum ConnectionStates
    Modem = 0x1,
    LAN = 0x2,
    Proxy = 0x4,
    RasInstalled = 0x10,
    Offline = 0x20,
    Configured = 0x40,

VB Signature:

  Private Declare Function InternetGetConnectedState Lib "wininet.dll" _
  (ByRef lpdwFlags As Int32, ByVal dwReserved As Int32) As Boolean

Private Enum ConnectionStates
    Modem = &H1
    LAN = &H2
    Proxy = &H4
    RasInstalled = &H10
    Offline = &H20
    Configured = &H40
End Enum

User-Defined Types:



Tips & Tricks:

Please add some!

Sample Code:



using System;
using System.Runtime.InteropServices;

namespace ConsoleApplication2
  internal class Program
   [DllImport("wininet.dll", SetLastError = true)]
   private static extern bool InternetGetConnectedState(out int lpdwFlags, int dwReserved);

   private static void Main(string[] args)
    int flags;
    bool isConnected = InternetGetConnectedState(out flags, 0);
    Console.WriteLine(string.Format("Is connected :{0} Flags:{1}", isConnected, flags));


Function Get_InternetConnectedState(ByRef p_lngFlags As Long, Optional ByRef p_return_str As String = "") As Boolean

   Dim lngFlags As Long

      lngFlags = 0
      Get_InternetConnectedState = False

      If InternetGetConnectedState(lngFlags, 0) Then
     If lngFlags And ConnectionStates.LAN Then
        'LAN connection.
        p_return_str = "LAN connection."
     ElseIf lngFlags And ConnectionStates.Modem Then
        'Modem connection.
        p_return_str = "Modem connection."
     ElseIf lngFlags And ConnectionStates.Proxy Then
        'Proxy connection.
        p_return_str = "Proxy connection."
     End If

     Get_InternetConnectedState = True

     'not connected.
     p_return_str = "Not connected."
     Get_InternetConnectedState = False
      End If

      p_lngFlags = lngFlags

End Function

Alternative Managed API:

Try NetworkInterface.GetIsNetworkAvailable() in the the System.Net.NetworkInformation namespace. It returns true when a network is available and false otherwise. See also: NOTE: this is all new in .NET 2.0!


Direct Link:

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

Access directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version