public static void AttachProcess(string filename, bool hidden = false)
{
var info = new ProcessStartInfo(filename);
Process found = ChildProcesses.Find(p => p.StartInfo.FileName == filename);
if (found != null && !hidden)
{
NativeMethods.SetForegroundWindow(found.MainWindowHandle);
return;
}
info.UseShellExecute = false;
info.RedirectStandardOutput = true;
if (hidden)
{
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
}
Process proc = Process.Start(info);
ChildProcesses.Add(proc);
}