When I get my servers DNS settings using the DNSServerSearchOrder property of my network card's settings, it returns the DNS server that it automatically resolves to, rather than a value that would indicate it is dynamic (such as null).
for example, to set my DNS servers to 'Obtain Automatically' I do:
ManagementBaseObject newDNS = myNICManagementObject.GetMethodParameters("SetDNSServerSearchOrder");
newDNS["DNSServerSearchOrder"] = null;
ManagementBaseObject setDNS = myNICManagementObject.InvokeMethod("SetDNSServerSearchOrder", newDNS, null);
Now, after I have set it to 'Obtain Automatically' with the other command I want to confirm it was set:
if( myNICManagementObject["DNSServerSearchOrder"] == null )
{
MessageBox.Show("DNS Servers Set to Dynamic!");
}
However, the above code does not return null (nor pop-up a messagebox) as expected. Instead it returns the DNS server that it dynamically figures out from my ISP.
Is there a way to determine programmatically that my DNS servers are set to 'Obtain Automatically'?
The only way I found is to read from the registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\\{Network_Adaptor_GUID}\NameServer
If NameServer
is empty - then DNS is dynamic, otherwise - static.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With