如题。先在此谢谢高手赐教

解决方案 »

  1.   

    http://www.c-sharpcorner.com/Code/2003/Aug/CheckInternetConnection.asp  
      

  2.   

    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 "";
                            }
                    }
      

  3.   

    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) ; 
        } 
     

    判断是否已经连网
      

  4.   

    提供一个最简单的方法
    在webservice中写一个web方法
    [WebMethod]
    public bool CheckState()
    {
       return true;
    }
    本地添加WEB引用
    调用bool State=false;
     try
    {
        State=WebService.CheckState();
    }
    catch
    {}
    如果State为true则在线!!反之就不在线!
      

  5.   

    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) ; 
        } 
     
    } 这个方法简单,哈哈
    谢谢各位了