public void EnableDHCP()
{
string ethernetDescription = "{5F632379-D5A7-4F26-89FC-C172212EDF65}";
ManagementClass wmi = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = wmi.GetInstances();
foreach (ManagementObject mo in moc)
{
//如果没有启用IP设置的网络设备则跳过
/* if (!(bool)mo["IPEnabled"])
continue;*/
string settingID = mo["SettingID"].ToString();
string descrption = mo["Description"].ToString();
if (settingID == ethernetDescription)
{ //重置DNS为空
mo.InvokeMethod("SetDNSServerSearchOrder", null);
//开启DHCP
mo.InvokeMethod("EnableDHCP", null);
}
}