Netsh.exe 运行 行

Netsh.exe run line

 System.Diagnostics.ProcessStartInfo netshprocess = new System.Diagnostics.ProcessStartInfo();
 netshprocess.FileName = "netsh.exe";
 string temp = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
 string user = "";
 for (int i = 0; i < temp.Length; i++)
 {
     user += temp[i];
     if (temp[i] == '\')
     {
         user = "";
     }
  }
  netshprocess.Arguments = "";
  netshprocess.Arguments = "http add urlacl url=http://+:7015/MeasurementTransferWCF user=" + user;
  netshprocess.UseShellExecute = true;
  System.Diagnostics.Process.Start(netshprocess).WaitForExit();

当我打开 netsh.exe 并手动输入代码为其工作的参数所具有的确切字符串(测试后删除了添加所以可以尝试在代码中完成)。我也尝试过 运行ning 以管理员模式运行,但它不起作用。我缺少什么才能到达 运行?

它不会出错,只是不会 运行 调用 process.start 时的争论

 System.Diagnostics.ProcessStartInfo netshprocess = new System.Diagnostics.ProcessStartInfo();
 netshprocess.FileName = "netsh.exe";


 string temp = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
 string user = "";
 for (int i = 0; i < temp.Length; i++)
 {
     user += temp[i];
     if (temp[i] == '\')
     {
         user = "";
     }
 }
 netshprocess.Verb = "runas";
 netshprocess.Arguments = "";
 netshprocess.Arguments = "http add urlacl url=http://+:7015/MeasurementTransferWCF user=" + user;
 netshprocess.UseShellExecute = true;
 try
 {

     System.Diagnostics.Process.Start(netshprocess).WaitForExit();
 }
 catch (Exception)

 { }

使用动词 运行 时,当用户单击“是”时,它会添加它,但如果他们单击“否”,您知道需要捕获异常,因为它将 git 失败到 运行错误