Search code examples
c#system.diagnostics

Process.Start does not open applications


how can I start 2 processes with the following code:

Process.Start(@"D:\Clients\Client1\program.exe");
Process.Start(@"D:\Clients\Client2\program.exe");

The routes are functional, the first process always opens

Both applications are the same, and the first application opens successfully for me, but the second application does not open. For the second application I noticed in the task manager in the details page that the application appears for a few seconds and disappears and does not open If I open the applications manually it works.

I'm interested in how I could do it to start applications using Process.Start () ?


Solution

  • Can you try to use this method to see if it solves your problem:

    public static void StartApplication(string applicationName, string argument = "", bool useShellExecute = true, bool createNoWindow = false)
    {
      Process task = new Process
      {
        StartInfo =
        {
          UseShellExecute = useShellExecute,
          FileName = applicationName,
          Arguments = argument,
          CreateNoWindow = createNoWindow
        }
      };
    
      task.Start();
    }
    

    You would use it like this:

    StartApplication(@"D:\Clients\Client1\program.exe");
    StartApplication(@"D:\Clients\Client2\program.exe");