title: Set DNS to 'Obtain automatically' programmatically
body: <p>Using C# on .NET, how do I set the DNS servers to 'Obtain automatically'? I can set the IP addresses to desired values like this.</p>
  
  <pre><code>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 and X.X.X.X are the IPs.
          string[] sIPs = { "X.X.X.X", "X.X.X.X" };
          mboDNS["DNSServerSearchOrder"] = sIPs;
          mObj.InvokeMethod("SetDNSServerSearchOrder", mboDNS, null);
       }
    }
  }
  </code></pre>
  
  <p>I've tried setting both IPs to null, like <code>sIps = { null, null };</code>, but that ends up not changing the settings at all.</p>