我想在捕获输出时运行具有提升权限的命令:
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
的。
任何可能的解决方案?