user3797438
user3797438

Reputation: 485

The requested operation requires elevation

I am trying to run an exe file from another user account name, it shows following error

    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)

Here is my code

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);

How to resolve this?

Upvotes: 14

Views: 22047

Answers (1)

Heinzi
Heinzi

Reputation: 172230

Unfortunately, you cannot do

  • run with elevated permissions and
  • redirect input/output

simultaneously.

Reason:

  • Verb is only recognized when UseShellExecute = true, but
  • redirecting IO requires UseShellExecute = false.

More information:

I guess in your situation you will have to skip using runas, but rather ensure that your application is already started with the correct user account/permissions. This should work, since processes started by elevated processes "inherit" elevation.

Upvotes: 21

Related Questions