简体   繁体   English

在Windows注册表中设置网络适配器DNS服务器不会立即应用

[英]Network adapter DNS servers not applied instantly when set in Windows registry

I would like to set DNS servers of a network adapter in Windows. 我想在Windows中设置网络适配器的DNS服务器。 Initially, I tried to use WMI for that purpose, but it turns out that it does not allow me to do what I want in some cases. 最初,我尝试将WMI用于此目的,但事实证明,在某些情况下,它不允许我做我想做的事情。 For instance, when I attempt to set DNS servers of an ethernet adapter with no cable connected to it, WMI returns an error saying that IP is not enabled for that adapter. 例如,当我尝试设置没有连接电缆的以太网适配器的DNS服务器时,WMI返回一个错误,指出该适配器未启用IP。 AFAIK, another problem is that it does not support managing IPv6 settings. AFAIK,另一个问题是它不支持管理IPv6设置。

So I decided to write to Windows registry directly: 因此,我决定直接写入Windows注册表:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip[6]\Parameters\Interfaces\[Interface GUID]\NameServer

Unfortunately, when I do that, it seems that the newly written settings are not applied instantly. 不幸的是,当我这样做时,似乎新写入的设置不会立即应用。 Because of that, I use WMI to disable and enable the adapter. 因此,我使用WMI禁用和启用适配器。

This solution, however, seems really cumbersome, and I'm wondering if the same thing can't be done in a 'clean' way. 但是,此解决方案似乎很麻烦,我想知道是否不能以“干净”的方式完成相同的事情。 I'm trying to do that in C#, .NET Framework 4.7.2. 我正在尝试在C#、. NET Framework 4.7.2中做到这一点。

What about NETSH tool? NETSH工具呢? Run it under Administrator. 在管理员下运行它。

Process.Start("netsh", "interface ip set dns \"NETWORK NAME\" static 8.8.8.8").WaitForExit();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 .net 中为网络适配器设置 dns 搜索后缀? - How do i set the dns search suffix for a network adapter in .net? 如何在通用Windows应用程序中将IP配置设置为网络适配器? - How to set IP config to network adapter in Universal windows app? 尝试使用 C# 在 Windows 注册表中设置 DWORD 值时出错 - Error when trying to set a DWORD value in the windows registry using C # 如何在Windows中为高级网络适配器属性设置Jumbo数据包和接收/传输缓冲区? - How to set Jumbo Packet and Receive/Transmit Buffers for advanced network adapter properties in Windows? Windows-7:在隐藏时禁用 inte.net 连接共享 on.network 适配器 state? - Windows-7:Disable internet connection sharing on network adapter when it's in hidden state? 禁用网络适配器时获取MAC地址? - Get MAC Address when network adapter is disabled? 如何获取Windows网络适配器使用的连接名称? - How to get connection name used by the Windows Network adapter? 应用ControlTemplate时无法设置GroupBox的标题 - Cannot set Header of GroupBox when ControlTemplate applied 网络适​​配器关闭时检测客户端断开连接 - Detect client disconnect when network adapter was turned off 通过Windows注册表以编程方式设置代理地址,端口,用户,密码 - Programmatically Set Proxy Address, Port, User, Password throught Windows Registry
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM