I have an interesting scenario. My executing process is QtAgent32.exe (Basically used for automated tests).
I have code to launch the application under test. If I manually started the app before running this EnsureAppIsRunning() method - it then gets the application from process like this:
_application = ApplicationUnderTest.FromProcess(processes[0]);
Now at the end of the test run, QtAgent32.exe shuts down and kills off the application - only if the application was created inside the process.
So again to restate, if I had manually opened the application, then it keeps it alive - which is the behavior I want.
So to try and solve this issue I went with a Process.Start(), and also tried the UseShellExecute - this didn't work.
I then moved on to the unmanaged route:
STARTUPINFO si = new STARTUPINFO();
PROCESS_INFORMATION pi = new PROCESS_INFORMATION();
CreateProcess(Constants.ApplicationUndertestPath, null, IntPtr.Zero, IntPtr.Zero, false, 0, IntPtr.Zero, null, ref si, out pi);
My question is, how can I start up and application from C#, so that it is treated as if it were a fully fledged external process (just like it was started by me manually). So that QtAgent32 won't kill it off later as a child process.