Direcciones DNS en Registro de Windows

Aquí podrás hablar de cualquier tema que no tenga un sección específica.
Hola foreros de AMSSpecialist!

Hoy les vengo pidiendo un gran favor... Se los ruego! Salven mi vida!
Sé muy bien que en el Registro de Windows está todo lo relacionado con dicho OS y sus configuraciones, Quisiera sabes (mejor dicho, necesito saber :c) Dónde es que debo modificar para cambiar las direcciones DNS, sé donde se modifican desde el Panel de Control y centro de Redes y todo eso, pero necesito saber como hacerlo desde el registro de Windows.

Por su atención, gracias
Espero puedan ayudarme.
Saludos Dow Sher
La cosa con las configs de windows es que requieren movidas turbias y poco documentadas, normalmente las dns las encuentras en un registro llamdo NameServer en regedit HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\
Interfaces\\{ interface uuid }
El problema es que para obtner ese uuid debes usar la funcion GetAdaptersInfo mediante c++ o luajit o c# o lo que sea y despues de aplicar los cambios debes de ejecutar una funcion oculta del sistema DnsFlushResolverCache() que esta en dnsapi.dll, para que se limpie el chache y tome efecto el cambio en ese moemnto en lugar de el proximo reicio.
Tambien he visto por ahi codigo en c# que podrias integrar facilmente con mi lua api
using System;
using System.Management;
namespace WindowsFormsApplication_CS
{
class NetworkManagement
{
/// <summary>
/// Set's a new IP Address and it's Submask of the local machine
/// </summary>
/// <param name="ip_address">The IP Address</param>
/// <param name="subnet_mask">The Submask IP Address</param>
/// <remarks>Requires a reference to the System.Management namespace</remarks>
public void setIP(string ip_address, string subnet_mask)
{
ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection objMOC = objMC.GetInstances();
foreach (ManagementObject objMO in objMOC)
{
if ((bool)objMO["IPEnabled"])
{
try
{
ManagementBaseObject setIP;
ManagementBaseObject newIP =
objMO.GetMethodParameters("EnableStatic");
newIP["IPAddress"] = new string[] { ip_address };
newIP["SubnetMask"] = new string[] { subnet_mask };
setIP = objMO.InvokeMethod("EnableStatic", newIP, null);
}
catch (Exception)
{
throw;
}
}
}
}
/// <summary>
/// Set's a new Gateway address of the local machine
/// </summary>
/// <param name="gateway">The Gateway IP Address</param>
/// <remarks>Requires a reference to the System.Management namespace</remarks>
public void setGateway(string gateway)
{
ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection objMOC = objMC.GetInstances();
foreach (ManagementObject objMO in objMOC)
{
if ((bool)objMO["IPEnabled"])
{
try
{
ManagementBaseObject setGateway;
ManagementBaseObject newGateway =
objMO.GetMethodParameters("SetGateways");
newGateway["DefaultIPGateway"] = new string[] { gateway };
newGateway["GatewayCostMetric"] = new int[] { 1 };
setGateway = objMO.InvokeMethod("SetGateways", newGateway, null);
}
catch (Exception)
{
throw;
}
}
}
}
/// <summary>
/// Set's the DNS Server of the local machine
/// </summary>
/// <param name="NIC">NIC address</param>
/// <param name="DNS">DNS server address</param>
/// <remarks>Requires a reference to the System.Management namespace</remarks>
public void setDNS(string NIC, string DNS)
{
ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection objMOC = objMC.GetInstances();
foreach (ManagementObject objMO in objMOC)
{
if ((bool)objMO["IPEnabled"])
{
// if you are using the System.Net.NetworkInformation.NetworkInterface you'll need to change this line to if (objMO["Caption"].ToString().Contains(NIC)) and pass in the Description property instead of the name
if (objMO["Caption"].Equals(NIC))
{
try
{
ManagementBaseObject newDNS =
objMO.GetMethodParameters("SetDNSServerSearchOrder");
newDNS["DNSServerSearchOrder"] = DNS.Split(',');
ManagementBaseObject setDNS =
objMO.InvokeMethod("SetDNSServerSearchOrder", newDNS, null);
}
catch (Exception)
{
throw;
}
}
}
}
}
/// <summary>
/// Set's WINS of the local machine
/// </summary>
/// <param name="NIC">NIC Address</param>
/// <param name="priWINS">Primary WINS server address</param>
/// <param name="secWINS">Secondary WINS server address</param>
/// <remarks>Requires a reference to the System.Management namespace</remarks>
public void setWINS(string NIC, string priWINS, string secWINS)
{
ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection objMOC = objMC.GetInstances();
foreach (ManagementObject objMO in objMOC)
{
if ((bool)objMO["IPEnabled"])
{
if (objMO["Caption"].Equals(NIC))
{
try
{
ManagementBaseObject setWINS;
ManagementBaseObject wins =
objMO.GetMethodParameters("SetWINSServer");
wins.SetPropertyValue("WINSPrimaryServer", priWINS);
wins.SetPropertyValue("WINSSecondaryServer", secWINS);
setWINS = objMO.InvokeMethod("SetWINSServer", wins, null);
}
catch (Exception)
{
throw;
}
}
}
}
}
}
}
Muchas gracias pabloko, ahora mismo me pongo a estudiar en eso... De nuevo muchas gracias, me has salvado la vida una reverencia :yes: