0

To launch an application from my C# program, I have tried the solutions listed in the thread at the following link : Launching an application (.EXE) from C#? .

I am facing a puzzling situation : no new window shows during the time my program runs, so I opened the processes list hoping to get more info. Here is what happens : when I double click my executable (case 1 : not using the code to execute the app), 5 different processes bearing the same name but different PIDs are raised and if I close the app, all of them shut down too so here I assume that all of these should run for my app to launch correctly; on the other hand, whenever I use the program to launch the app, only one process is initiated and no window is displayed (this is not a matter of ProcessStartInfo since I made sure to change the parameters so that a new window is displayed if needed). Any idea as to why there are two different behaviors depending on whether I "double click" manually or launch through a C# instruction ? If it is an "argument matter" is there a way for me to get more intelligence about the arguments that are implicitly used when I double click (and do not provide with my script as for now) ?

Thanks !

Appendix :

C# code :

using System;
using System.Diagnostics;
using System.IO;

namespace GradeBook
{
    class Program
    {
        static void Main(string[] args)
        {
            ProcessStartInfo start = new ProcessStartInfo();
            start.Arguments = "";
            Directory.SetCurrentDirectory("C:\\Users\\sthg\\AppData\\Local\\Programs\\sthg");
            start.FileName = "myApp.exe";
            start.WindowStyle = ProcessWindowStyle.Normal;
            start.CreateNoWindow = false;
            int exitCode;

            using (Process proc = Process.Start(start))
            {
                proc.WaitForExit();
                exitCode = proc.ExitCode;
            }
        }
    }
}
J. Valjean
  • 35
  • 7
  • 1
    If you're launching from a shortcut, right click and check the exe and arguments being used. – Magnetron Jan 09 '20 at 15:39
  • 2
    You have to check: 1) how your link starts the app; 2) in `ProcessStartInfo` you have to set `WorkingDir`, not use `Directory.SetCurrentDirectory`! – Marco Jan 09 '20 at 15:40
  • I've tried to look for the args given by the shortcut, actually there aren't any, how can I look at how my link starts the app ? – J. Valjean Jan 09 '20 at 16:01
  • Did you set `WorkingDir` and tried to run the exe with your app again? What happened? – Marco Jan 09 '20 at 16:05
  • Yes I set the workingdir the way you told me to : start.WorkingDirectory = "C:\\Users\\sthg\\AppData\\Local\\Programs\\sthg"; But same behavior, only one instance of a process – J. Valjean Jan 09 '20 at 16:08
  • 2
    Use the process explorer to see what actually happened when either thing was launched. – Señor CMasMas Jan 09 '20 at 16:41
  • Already done (see in the post) – J. Valjean Jan 13 '20 at 15:25

0 Answers0