I am working on a Winform application. On button click I need to launch a new 3rd party exe. For this I am using the following code:
private void btnUserMgmt_Click(object sender, EventArgs e)
{
if (!IsAlreadyRunning())
{
System.Diagnostics.Process proc = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = strAppPath + "ReveaLINXUserMgmt/ReveaLINXUserMgmt.exe",
Arguments = "192.168.0.121\\TESTDBSERVER",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true,
}
};
proc.Start();
}
}
private bool IsAlreadyRunning()
{
var processExists = System.Diagnostics.Process.GetProcesses().Any(p => p.ProcessName.Contains("ReveaLINXUserMgmt"));
return processExists;
}
Now it is launching fine and running on the top of my main application window.
I need when some one again click btnUserMgmt
button. If ReveaLINXUserMgmt.exe is already running and in minimized state, it will come on top of window.
If user closes the main application, child exe will also to be closed