• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
wjshan0808

Learn from yesterday, Live for today, For a better tomorrow.
 ————wjshan0808

博客园    首页    新随笔    联系   管理    订阅  订阅

检测网络状态

        /// <summary>
        /// Retrieves the connected state of the local system
        /// </summary>
        /// <param name="lpdwFlags">Pointer to a variable that receives the connection description. This parameter may return a valid flag even when the function returns FALSE. This parameter can be one or more of the following values.</param>
        /// <param name="dwReserved">This parameter is reserved and must be 0.</param>
        /// <returns>Returns TRUE if there is an active modem or a LAN Internet connection, or FALSE if there is no Internet connection, or if all possible Internet connections are not currently active. For more information, see the Remarks section. 
        /// When InternetGetConnectedState returns FALSE, the application can call GetLastError to retrieve the error code</returns>
        [DllImport("wininet.dll", EntryPoint = "InternetGetConnectedState")]
        public extern static bool InternetGetConnectedState(out StateFlags lpdwFlags, int dwReserved);


    public enum StateFlags : int
    {
        /// <summary>
        /// Local system uses a modem to connect to the Internet.
        /// </summary>
        INTERNET_CONNECTION_MODEM = 0x01,
        /// <summary>
        /// Local system uses a local area network to connect to the Internet.
        /// </summary>
        INTERNET_CONNECTION_LAN = 0x02,
        /// <summary>
        /// Local system uses a proxy server to connect to the Internet.
        /// </summary>
        INTERNET_CONNECTION_PROXY = 0x04,
        /// <summary>
        /// No longer used.
        /// </summary>
        INTERNET_CONNECTION_MODEM_BUSY = 0x08,
        /// <summary>
        /// Local system has RAS installed.
        /// </summary>
        INTERNET_RAS_INSTALLED = 0x10,
        /// <summary>
        /// Local system is in offline mode.
        /// </summary>
        INTERNET_CONNECTION_OFFLINE = 0x20,
        /// <summary>
        /// Local system has a valid connection to the Internet, but it might or might not be currently connected.
        /// </summary>
        INTERNET_CONNECTION_CONFIGURED = 0x40
    }

 


posted @ 2015-01-13 16:05  wjshan0808  阅读(180)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3