C#实现更改IP功能源代码

 这是一个很好的源码,给大家一起分享一下。

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

    ///

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

你可能感兴趣的:(C#)