请求的操作需要提升

use*_*438 6 c#

我试图从另一个用户帐户名运行exe文件,它显示以下错误

    System.ComponentModel.Win32Exception: The requested operation requires an elevation
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start()
    at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
Run Code Online (Sandbox Code Playgroud)

这是我的代码

ProcessStartInfo pro = new ProcessStartInfo(application);
pro.UseShellExecute = false;
pro.Verb = "runas";
pro.WorkingDirectory = workingdirectory;
pro.RedirectStandardInput = true;
pro.RedirectStandardOutput = true;
pro.CreateNoWindow = true;

Process process = Process.Start(pro);
Run Code Online (Sandbox Code Playgroud)

怎么解决这个?

Hei*_*nzi 15

不幸的是,你做不到

  • 以提升的权限运行
  • 重定向输入/输出

同时.

原因:

  • Verb只有当UseShellExecute = true,但是
  • 重定向IO需要UseShellExecute = false.

更多信息:

我想在您的情况下,您将不得不跳过使用runas,而是确保您的应用程序已经使用正确的用户帐户/权限启动.这应该有效,因为由提升的进程启动的进程"继承"高程.