这是一个很好的源码,给大家一起分享一下。
mo.InvokeMethod("EnableStatic", iObj, null);
iObj = mo.GetMethodParameters("SetGateways");
iObj["DefaultIPGateway"] = gateways;
iObj["GatewayCostMetric"] = gatewayCostMetric;
oObj = mo.InvokeMethod("SetGateways", iObj, null);
iObj = mo.GetMethodParameters("SetDNSServerSearchOrder");
iObj["DNSServerSearchOrder"] = dnsServer;
oObj = mo.InvokeMethod("SetDNSServerSearchOrder", iObj, null);
}
}
///<summary>DHCPEnabled</summary>
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);
}
}
}
}