Apologies for this mess, I started a few days ago and I'am still trying to learn. My code :
private void button1_Click(object sender, EventArgs e)
{
ManagementScope oMs = new ManagementScope();
ObjectQuery oQuery =
new ObjectQuery("Select * From Win32_NetworkAdapter");
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);
ManagementObjectCollection oReturnCollection = oSearcher.Get();
foreach (ManagementObject oReturn in oReturnCollection)
{
if (oReturn.Properties["NetConnectionID"].Value != null)
{
// I want the result from this pasted into the "Network Adapter" prompt
Console.WriteLine(oReturn.Properties["NetConnectionID"].Value);
// This is probably 100% wrong, sorry.
String NetworkAdapter = Console.WriteLine(oReturn.Properties["NetConnectionID"].Value);
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.Start();
// I want to insert the Name of a network adapter into this command prompt, but I can't seem to manage it.
process.StandardInput.WriteLine("netsh interface ipv4 set dns "NetworkAdapter" static 8.8.8.8");
process.StandardInput.WriteLine("netsh interface ipv4 add dns "NetworkAdapter" 8.8.4.4 index=2");
process.StandardInput.Flush();
process.StandardInput.Close();
process.WaitForExit();
Console.WriteLine(process.StandardOutput.ReadToEnd());
Console.Read();
}
}
}
The idea is that when I press the button, it will detect my active Network Adapter name and paste it into standard dns change through cmd.exe prompt. I'm starting to think I've made it harder for myself than it has to be.
Thank you for any help.