【小技巧】C#判斷電腦是否聯網


using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; //添加特殊命名空間
using System.Runtime.InteropServices; namespace GPS解析上位機_在線版_ { public partial class Form1 : Form     { [DllImport("wininet")] //判斷網絡狀況的方法,返回值true為連接,false為未連接 
        public extern static bool InternetGetConnectedState(out int conState, int reder); public Form1() { InitializeComponent(); int i = 0; if((InternetGetConnectedState(out i, 0)==true)) { MessageBox.Show("設備聯網正常!"); } else { MessageBox.Show("設備不可聯網!"); } } private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM