CSDN博客

img zenolee

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

发表于2008/9/29 12:41:00  207人阅读

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

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

0 0

相关博文

我的热门文章

img
取 消
img