1
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並手動輸入代碼對參數有效的確切字符串時,似乎無法通過代碼運行它(測試然後刪除了添加這樣可以嘗試在代碼中執行)。我也嘗試以管理員模式運行,但它不起作用。我錯過了什麼讓它運行?Netsh.exe運行行
它不對錯誤,它只是不運行arguement時的Process.Start被稱爲
刪除'catch(Exception){}'並找出你自己。您也可能想要閱讀過程的標準和錯誤輸出。 – CodeCaster 2015-03-03 11:16:31
它沒有得到cought在try catch,它不會崩潰,如果它不存在它打開netsh和關閉只是沒有運行的爭論@codecaster – 2015-03-03 11:18:49