我有这个改变DNS的功能:
/**
* Change dns
*
* @param bool
*/
private void changeDns(bool develop)
{
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)
{
if (develop == true)
{
// Set dns
mboDNS["DNSServerSearchOrder"] = this.dnsServer;
// Log info
foreach (String dns in this.dnsServer) {
this.addLog(dns, "DNS servers change to:", Color.Green);
}
}
else
{
// Set dns
mboDNS["DNSServerSearchOrder"] = null;
// Log info
this.addLog("DHCP", "DNS servers change to:", Color.Green);
}
// Change dns
mObj.InvokeMethod("SetDNSServerSearchOrder", mboDNS, null);
}
}
}
}
但现在我需要另一种方式。win32如何获取dns?
我从 MSDN尝试了这段代码,但它返回了大约 10 个结果。