Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How can you detect if User IS ONLINE?

How can you detect if User IS ONLINE?

Scheduled Pinned Locked Moved C#
question
3 Posts 3 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cdengler
    wrote on last edited by
    #1

    Does anyone know of a "clean" way to detect if a user is online? Code examples are appreciated.

    A J 2 Replies Last reply
    0
    • C cdengler

      Does anyone know of a "clean" way to detect if a user is online? Code examples are appreciated.

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      P/Invoke BOOL InternetGetConnectedState(LPDWORD lpdwFlags, DWORD dwReserved)

      1 Reply Last reply
      0
      • C cdengler

        Does anyone know of a "clean" way to detect if a user is online? Code examples are appreciated.

        J Offline
        J Offline
        John Mautari
        wrote on last edited by
        #3

        using System.Runtime.InteropServices; ... public class InternetConnection { [DllImport("wininet.dll")] public static extern bool InternetGetConnectedStateEx(out int lpdwFlags, byte[] szConn, int iConnSize, int dwReserved); /// /// Status da conexão /// public enum Status: int { /// /// Local system uses a modem to connect to the Internet. /// INTERNET_CONNECTION_MODEM = 1, /// /// Local system uses a local area network to connect to the Internet. /// INTERNET_CONNECTION_LAN = 2, /// /// Local system uses a proxy server to connect to the Internet. /// INTERNET_CONNECTION_PROXY = 4, /// /// Local system has RAS installed. /// INTERNET_RAS_INSTALLED = 16, /// /// Local system is in offline mode. /// INTERNET_CONNECTION_OFFLINE = 32, /// /// Local system has a valid connection to the Internet, but it might or might not be currently connected. /// INTERNET_CONNECTION_CONFIGURED = 64 } /// /// Returns true if connected /// public static bool Connected { get { bool bConn = false; int flags = 0; byte [] cName = new byte[512]; if(InternetGetConnectedStateEx(out flags, cName, 512, 0)) { bConn = true; } return bConn; } } public InternetConnection() { } } ... InternetConnection inet = new InternetConnection(); if(inet.Connected) { ... } else { // not connected } Cheers, John

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups