public static void UnsetDNS() { var CurrentInterface = GetActiveEthernetOrWifiNetworkInterface(); if (CurrentInterface == null) return; ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection objMOC = objMC.GetInstances(); foreach (ManagementObject objMO in objMOC) { if ((bool)objMO["IPEnabled"]) { if (objMO["Description"].ToString().Equals(CurrentInterface.Description)) { ManagementBaseObject objdns = objMO.GetMethodParameters("SetDNSServerSearchOrder"); if (objdns != null) { objdns["DNSServerSearchOrder"] = null; objMO.InvokeMethod("SetDNSServerSearchOrder", objdns, null); } } } } }