- 注册时间
- 2011-5-16
- 最后登录
- 2021-1-13
- 阅读权限
- 200
- 积分
- 133067
- 精华
- 1
- 帖子
- 154
|
/// ManagementObjectSearcher
/// </summary>
/// <returns></returns>
public static string GetState()
{
//using System.Management;
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 "";
}
}
}
} |
|