1

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.

JL.
  • 78,954
  • 126
  • 311
  • 459
  • possible duplicate of [Creating a new process that's not a child of the creating process](http://stackoverflow.com/questions/12068647/creating-a-new-process-thats-not-a-child-of-the-creating-process) – Biscuits Apr 15 '15 at 09:36
  • See also http://stackoverflow.com/questions/1035213/process-start-and-the-process-tree – Biscuits Apr 15 '15 at 09:36

2 Answers2

2

The only way that comes to mind is through the use of a proxy executable, your application launches the proxy - which then becomes a child process of your process - and the proxy launches the desired application, and then exits.

You could use the same CreateProcess method you used in C# - I'm using the following native code to achieve the same:

CreateProcess(nullptr, pCommandLine.get(), nullptr, nullptr, FALSE, CREATE_SUSPENDED, nullptr, dir.c_str(), &inf, &pinf))
aevitas
  • 3,753
  • 2
  • 28
  • 39
2

I used explorer as the proxy:

ProcessStartInfo processInfo;

processInfo = new ProcessStartInfo("explorer.exe", Constants.ApplicationUndertestPath);
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = false;
processInfo.RedirectStandardOutput = false;

Process.Start(processInfo);
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
JL.
  • 78,954
  • 126
  • 311
  • 459