c# - How yo know if my PC is connected to Internet?

Discussion in '.NET' started by pinkerton1981, Oct 31, 2011.

  1. pinkerton1981

    pinkerton1981 New Member

    Joined:
    Oct 29, 2011
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    Another tip today! So, to know if your PC is connected to Internet, you can use the InternetGetConnectedState function from wininet.dll like this:
    Code:
    [COLOR=DarkBlue]using System.Runtime.InteropServices;
    
    // API declaration
    [DllImport("[COLOR=blue][B]wininet.dll[/B][/COLOR]")]
    public extern static bool [B][COLOR=blue]InternetGetConnectedState[/COLOR][/B]( out int Description, int ReservedValue ) ;
    
    // API using
    public static bool IsConnected()
    {
         int Desc ;
         return[COLOR=blue][B] InternetGetConnectedState[/B][/COLOR]( out Desc, 0 ) ;
    }[/COLOR]
    Be careful to the ghosts tonight ;)

    pinkerton1981
     
  2. hu_yang

    hu_yang New Member

    Joined:
    Jan 22, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    net-informations.com/csprj/communications/internet-connection.htm
     

Share This Page