日期:2014-05-18 浏览次数:20841 次
static void SwitchToDHCP() { ManagementBaseObject inPar = null; ManagementBaseObject outPar = null; ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) { if (!(bool)mo["IPEnabled"]) continue; inPar = mo.GetMethodParameters("EnableDHCP"); outPar = mo.InvokeMethod("EnableDHCP", inPar, null); break; } }
//自动获取IP public void EnableDHCP() { foreach (ManagementObject mo in moc) { if (!(bool)mo["IPEnabled"]) continue; if (!(bool)mo["DHCPEnabled"]) { iObj = mo.GetMethodParameters("EnableDHCP"); oObj = mo.InvokeMethod("EnableDHCP", iObj, null); } } }