Reputation: 1058
I am using the following code within a program that does not have elevated privileges
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);
The end user is asked to select whether they wish to run the program in elevated mode or not. The above however is not starting the program 'As Administrator' when runAsAdministrator is true. I have ran the 'fileToExcute' manually 'As Administrator' and it prompts to make changes to the computer.
I then added a manifest to the 'fileToExecute' to run with elevated privileges every time and when running that program directly I am properly prompted to confirm permission to make changes to the computer. When I run the above program that uses the above code, I get:
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
I really want the first option to work. I've tried everything and can't work out why the first option is not working.
Upvotes: 0
Views: 1572
Reputation: 1058
I changed my code and did not use the pInfo configuration options. I just changed everything to p.verb = "runas" etc and it is now working.
Upvotes: 0
Reputation: 13601
You can't combine the Verb
property with UseShellExecute = false
, since verbs rely on that functionality. Set UseShellExecute
to true
and it should work.
Upvotes: 4