0
와 실행 명령 :C# : 출력을 캡처하는 동안 나는 높은 권한으로 명령을 실행하고 싶습니다 상승 된 권한과 캡처 출력
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";
가 RedirectStandardOutpu
호환되지 인 startInfo.UseShellExecute = true;
이 필요하다는 것이다.
가능한 해결책은 있습니까?
읽고 실행에 높은 권한을 요청하는 프로그램을 수행합니다. 그래서 나는 아직도 stdout을 잡을 수 없다. 상승 된 콘솔의 출력을 _steal_ 원본 콘솔에 복사하고 싶습니다. – antonio
"runas"동사를 제거하고 UseShellExecute를 false로 설정했는지 확인하십시오. – Gusman
아무 조치도 취하지 않았습니다. 나는 높은 콘솔 앱이 별개의 콘솔에서 열리는 것이 정상이라고 생각한다. 요점은 새로운 높은 콘솔에서 출력을 캡처하여 원본 콘솔로 전송하는 것입니다. – antonio