我的应用程序启动“C:\ Windows \ System32 \ Msra.Exe”来控制域计算机。有没有一种方法可以捕获此msra.Exe显示的错误消息。 (即来自msra.exe的内部错误消息,而不是来自我的应用程序的内部错误消息)。 该应用程序本身是一个Windows窗体应用程序。C# - 捕获Windows应用程序输出
任何帮助表示赞赏。
启动MSRA的代码位于下方...它只是完整应用程序的一个片段。
string msra = "C:\\Windows\\System32\\runas.exe";
string domainname = "**********";
string domaincontroller = "*************";
if (File.Exists(msra) == false)
{
System.Windows.Forms.MessageBox.Show("Runas.exe not found.\n\rPlease contact your internal IT support.", "Fatal Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
}
else
{
try
{
Process p = new Process();
p.StartInfo.UseShellExecute = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
p.StartInfo.ErrorDialog = true;
p.StartInfo.FileName = msra;
p.StartInfo.Arguments = "/noprofile /netonly /user:" + domainname + "\\" + username + " \"cmd /server:" + domaincontroller + " /C msra.exe /offerra " + computerip + "\"";
p.Start();
p.Dispose();
Thread.Sleep(1700);
SendKeys.SendWait(password);
SendKeys.SendWait("{ENTER}");
}
catch
{
System.Windows.Forms.MessageBox.Show("MSRA could not be started for an unknown reason");
}
}
可能重复[控制台输出重定向到单独的程序C#文本框(HTTP://计算器.com/questions/415620/redirect-console-output-to-textbox-in-separate-program-c-sharp) – tenfour