9

I need to run an elevated command in my c# application and get the output.

I'm creating a new System.Diagnostics.Process instance, coupled with a new System.Diagnostics.ProcessStartInfo instance.

The command is being sent to cmd.exe, and unfortunately may require elevated user access (meaning UseShellExecute = true and Verb = "runas" must be present).

As a result of using UseShellExecute = true, RedirectStandardOutput will not work.

It's important I record the output of the command, but the only way I can see of getting this is adding something like > output.txt to the argument list, then calling System.IO.File.ReadAllText to read the result.

Can anyone think of less hacky way?

maxp
  • 24,209
  • 39
  • 123
  • 201
  • possible duplicate of [Redirect standard output and prompt for UAC with ProcessStartInfo](http://stackoverflow.com/questions/18660014/redirect-standard-output-and-prompt-for-uac-with-processstartinfo) – Alex Netkachov Jul 28 '15 at 14:13

0 Answers0