I am trying to run logman.exe
for a elevated CMD
, for this below code I tried,
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = @"C:\Windows\System32\cmd.exe",
Arguments = "cmd /k logman.exe PerfCounterCustom | findstr \"Root\"",
Verb = "runas",
UseShellExecute = true,
}
};
try
{
proc.Start();
while (!proc.StandardOutput.EndOfStream)
{
string line = proc.StandardOutput.ReadLine();
}
Console.WriteLine("Successfully elevated!");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
And it's giving error output like,
System.InvalidOperationException: StandardOut has not been redirected or the process hasn't started yet.
at System.Diagnostics.Process.get_StandardOutput()
2 Questions,
- when I am running application
exe
, it's showing 2CMD
window, the 1st one showing error and 2nd one showing result for argument"cmd /k logman.exe PerfCounterCustom | findstr \"Root\""
[Root Path]
how to disable showing both window?
- Why I am getting this error?