C#检测当前用户网络是否连接 代码如下: [DllImport("wininet.dll")] private extern static bool InternetGetConnectedState(int Description, int ReservedValue); public static bool IsConnectedToInternet() { int Desc = 0; return InternetGetConnectedState(Desc, 0); } private void button1_Click(object sender, EventArgs e) { //检测网络状态 if (!IsConnectedToInternet()) { MessageBox.Show("当前不能连接到服务器,请检查网络、防火墙等设备!"); return; } } 作者:灵雨飘零 出处:http://www.cnblogs.com/kingboy2008/ 本文版权归作者和博客园、CSDN共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。该文章也同时发布在我的独立博客中-博客园—灵雨飘零和CSDN—灵雨飘零。