Reputation: 485
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
Reputation: 172230
Unfortunately, you cannot do
simultaneously.
Reason:
Verb
is only recognized when UseShellExecute = true
, butUseShellExecute = 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