花了一整天时间理清了管理员权限的问题,怪我懂得太少
vs2013上写的控制台应用程序,如下代码直接用在Main中。源码测试的是更改本地ip、网关等的功能。
C#用管理员调用cmd
string str = "netsh interface ip set address name=\"本地连接\" source=static addr=10.0.0.28 mask=255.255.255.0 gateway=10.0.0.1 gwmetric=1";
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/c C:\\Windows\\System32\\cmd.exe";
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.Redirec