1

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

Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
Rajeev Kumar
  • 4,901
  • 8
  • 48
  • 83
  • @ScottChamberlain: There's a big difference between making a single instance application (where you control the code), and launching a single instance of a third-party application. Your duplicate was invalid. – Ben Voigt Dec 05 '14 at 06:52
  • It is third party exe. so won't be able to edit its class libraries – Rajeev Kumar Dec 05 '14 at 06:53
  • 2
    If you use CreateNoWindow = true and the app "runs on top" then something went drastically wrong. There's in general limited wisdom in manipulating windows owned by another process. Set the button's Enabled property to *false* when you start the process. Use the Process.Exited event to set it back to *true*. Problem solved, the user knows how to use the taskbar button. – Hans Passant Dec 05 '14 at 06:58
  • @HansPassant Good idea for avoiding writting code for checking the exe instance is running or not. I am going to use it – Rajeev Kumar Dec 05 '14 at 07:06

0 Answers0