Best way to programmatically configure network adapters in .NET

后端 未结 5 635
梦毁少年i
梦毁少年i 2020-12-01 11:18

I have an application written in C# that needs to be able to configure the network adapters in Windows. I have this basically working through WMI, but there are a couple of

5条回答
  •  没有蜡笔的小新
    2020-12-01 11:24

    with the help of @PaulB's answers help

    NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
    Process p = new Process();
    ProcessStartInfo psi = new ProcessStartInfo("netsh", "interface ip set address " + nics[0].Name + " static 192.168." + provider_ip + "." + index + " 255.255.255.0 192.168." + provider_ip + ".1 1");
    p.StartInfo = psi;
    p.StartInfo.Verb = "runas";
    p.Start();
    

提交回复
热议问题