Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The requested operation requires elevation

Tags:

c#

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?

like image 303
user3797438 Avatar asked Sep 01 '14 07:09

user3797438


People also ask

How do you bypass this operation requires elevation?

What Does 'The Requested Operation Requires Elevation' Mean in Windows 10? As the error message indicates, you can only gain access to or take ownership of the file/folder by getting the elevated permission of a local administrator. So, to resolve the problem, you need to change the ownership of the drive.

How do I run elevation as administrator?

In the Search box, type cmd.exe but do NOT press Enter. In the search results window, under Programs, right-click on the program cmd.exe. In the pop-up menu, select Run As Administrator.

How do I fix the requested operation requires elevation in Windows 7?

For Windows 7 and Windows 2008 R2, click User Account Control Settings link. This opens the User Account Control Settings dialog showing the control level. Drag and choose the control level to Never Notify and click OK.

What does elevation mean in computers?

The term “elevation” simply means that you need a “higher” level of access to the system than you currently have. The privileges associated with your current login need to be temporarily raised or “elevated” to a more privileged or powerful level.


1 Answers

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:

  • Elevating privileges doesn't work with UseShellExecute=false

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.

like image 199
Heinzi Avatar answered Sep 22 '22 02:09

Heinzi