C#判断当前计算机是否已经连接网络

  //判断网络连接 
        [DllImport("wininet")]
        private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
     
        private void btnOK_Click(object sender, EventArgs e)
        {
            //判断是否联网 
            int i = 0;
            if (InternetGetConnectedState(out i, 0))
            {
                //联网
                MessageBox.Show("Thylx提醒您:你的计算机已连接到网络上!");
            }
            else
            {
                //断网
                MessageBox.Show("Thylx提醒您:本地连接已断开!");

            }

        }

发布了9 篇原创文章 · 获赞 20 · 访问量 8604

猜你喜欢

转载自blog.csdn.net/liuqiao0327/article/details/46789073
今日推荐