c# - Set DNS to 'Obtain automatically' programmatically -
using c# on .net, how set dns servers 'obtain automatically'? can set ip addresses desired values this.
managementclass mclass = new managementclass("win32_networkadapterconfiguration"); managementobjectcollection mobjcol = mclass.getinstances(); foreach (managementobject mobj in mobjcol) { if ((bool)mobj["ipenabled"]) { managementbaseobject mbodns = mobj.getmethodparameters("setdnsserversearchorder"); if (mbodns != null) { //assume x.x.x.x , x.x.x.x ips. string[] sips = { "x.x.x.x", "x.x.x.x" }; mbodns["dnsserversearchorder"] = sips; mobj.invokemethod("setdnsserversearchorder", mbodns, null); } } }
i've tried setting both ips null, sips = { null, null };
, ends not changing settings @ all.
try setting dnsserversearchorder null instead of using array of null strings.
managementclass mclass = new managementclass("win32_networkadapterconfiguration"); managementobjectcollection mobjcol = mclass.getinstances(); foreach (managementobject mobj in mobjcol) { if ((bool)mobj["ipenabled"]) { managementbaseobject mbodns = mobj.getmethodparameters("setdnsserversearchorder"); if (mbodns != null) { mbodns["dnsserversearchorder"] = null; mobj.invokemethod("setdnsserversearchorder", mbodns, null); } } }
Comments
Post a Comment