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

来源:互联网 发布:知远防务 招聘 编辑:程序博客网 时间:2024/06/05 11:12
  //判断网络连接 
        [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提醒您:本地连接已断开!");

            }

        }

0 0