我使用不具有更高權限啓動進程「以管理員身份」不工作
ProcessStartInfo pInfo = new ProcessStartInfo();
pInfo.FileName = fileToExcecute;
pInfo.UseShellExecute = false;
pInfo.RedirectStandardOutput = false;
pInfo.RedirectStandardError = false;
pInfo.CreateNoWindow = true;
if (runAsAdministrator)
pInfo.Verb = "runas";
Process p = Process.Start(pInfo);
最終用戶被要求選擇他們是否希望在運行程序的程序中下面的代碼提升模式與否。 但是,當runAsAdministrator爲真時,上述內容不會以「管理員」身份啓動程序。我已經手動'以管理員身份'運行'fileToExcute',並提示對計算機進行更改。
然後,我在'fileToExecute'中添加了一個清單,每次運行該程序時都會提升權限,並直接運行該程序時,系統會提示您確認是否允許對計算機進行更改。 當我運行使用上面的代碼上面的程序,我得到:
System.ComponentModel.Win32Exception (0x80004005):
The requested operation requires elevation at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start() at System.Diagnostics.Process.Start(ProcessStartInfo startInfo) at
#HLg.#ic.#zNg(String #ANg) in #pOg:line 135
我真的想第一個選項工作。我已經嘗試了一切,不能解決爲什麼第一個選項不起作用。
謝謝。我發現這非常令人沮喪:-( – David