【发布时间】:2017-06-12 13:18:11
【问题描述】:
我想在捕获输出时以提升的权限运行命令:
using System.Diagnostics;
namespace SO
{
class Program
{
static void Main(string[] args)
{
ProcessStartInfo startInfo = new ProcessStartInfo("FSUTIL", "dirty query c:");
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.Verb = "runas";
var proc = new Process();
proc.StartInfo = startInfo;
proc.Start();
proc.WaitForExit();
string output = proc.StandardOutput.ReadToEnd();
System.Console.WriteLine(output);
}
}
}
问题是startInfo.Verb = "runas"; 需要startInfo.UseShellExecute = true;,与RedirectStandardOutpu 不兼容。
任何可能的解决方案?
【问题讨论】:
标签: c# process elevated-privileges elevation privilege-elevation