能不能判断用户是否已经连上Internet(winform) 如题。先在此谢谢高手赐教 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.c-sharpcorner.com/Code/2003/Aug/CheckInternetConnection.asp WMI:public string NetStatus() { ManagementObjectCollection objects; string status = ""; ManagementObjectSearcher searcher = new ManagementObjectSearcher(); searcher.Query.QueryString = "Select * From Win32_NetworkAdapter "; objects = searcher.Get(); foreach(ManagementObject obj in objects) { foreach(PropertyData p in obj.Properties) { if(p.Name.Equals("NetConnectionStatus")) { if(p.Value!=null) { status = p.Value.ToString(); } } } } switch(status) { case "0": return "Disconnected"; case "1": return "Connecting ..."; case "2": return "Connected"; case "3": return "Disconnecting ..."; case "4": return "Hardware not present"; case "5": return "Hardware disabled"; case "6": return "Hardware malfunction"; case "7": return "Media disconnected"; case "8": return "Authenticating"; case "9": return "Authentication succeeded"; case "10": return "Authentication failed"; default: return ""; } } public class InternetCS { //Creating the extern function [DllImport("wininet.dll")] private extern static bool InternetGetConnectedState(int Description,int ReservedValue); //Creating a function that uses the API function public static bool IsConnectedToInternet() { int Desc=0; return InternetGetConnectedState(Desc,0) ; } } 判断是否已经连网 提供一个最简单的方法在webservice中写一个web方法[WebMethod]public bool CheckState(){ return true;}本地添加WEB引用调用bool State=false; try{ State=WebService.CheckState();}catch{}如果State为true则在线!!反之就不在线! NewBo(^_^) 你的方法还是他麻烦public class InternetCS { //Creating the extern function [DllImport("wininet.dll")] private extern static bool InternetGetConnectedState(int Description,int ReservedValue); //Creating a function that uses the API function public static bool IsConnectedToInternet() { int Desc=0; return InternetGetConnectedState(Desc,0) ; } } 这个方法简单,哈哈谢谢各位了 C#取图片操作问题 直接在单独的aspx上写程序代码和在aspx页的aspx.cs上面写程序代码两者运行时有区别吗? 请问怎么查看sql server2005的服务器名? 大家能否一起讨论个问题! xml信息读写问题? ???这里人多,问个sql server的问题 怎样判断 DATASET 中的 DATATABLE 是否有行, 或最大的行号? 求高手提供用C#画平面等值线算法以及源码 谁能给我BBS 系统论文文档,谢谢咯 一个简单问题,怎样得到控制台程序当前路径??? 增加主菜单以后有一条该死的白线!怎么能去掉? 问!!!!!!!!!FFT
public string NetStatus()
{
ManagementObjectCollection objects;
string status = "";
ManagementObjectSearcher searcher = new ManagementObjectSearcher();
searcher.Query.QueryString = "Select * From Win32_NetworkAdapter ";
objects = searcher.Get();
foreach(ManagementObject obj in objects)
{
foreach(PropertyData p in obj.Properties)
{
if(p.Name.Equals("NetConnectionStatus"))
{
if(p.Value!=null)
{
status = p.Value.ToString();
}
}
}
}
switch(status)
{
case "0":
return "Disconnected";
case "1":
return "Connecting ...";
case "2":
return "Connected";
case "3":
return "Disconnecting ...";
case "4":
return "Hardware not present";
case "5":
return "Hardware disabled";
case "6":
return "Hardware malfunction";
case "7":
return "Media disconnected";
case "8":
return "Authenticating";
case "9":
return "Authentication succeeded";
case "10":
return "Authentication failed";
default:
return "";
}
}
{
//Creating the extern function
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(int Description,int ReservedValue);
//Creating a function that uses the API function
public static bool IsConnectedToInternet()
{
int Desc=0;
return InternetGetConnectedState(Desc,0) ;
}
}
判断是否已经连网
在webservice中写一个web方法
[WebMethod]
public bool CheckState()
{
return true;
}
本地添加WEB引用
调用bool State=false;
try
{
State=WebService.CheckState();
}
catch
{}
如果State为true则在线!!反之就不在线!
你的方法还是他麻烦public class InternetCS
{
//Creating the extern function
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(int Description,int ReservedValue);
//Creating a function that uses the API function
public static bool IsConnectedToInternet()
{
int Desc=0;
return InternetGetConnectedState(Desc,0) ;
}
} 这个方法简单,哈哈
谢谢各位了