I finally managed to solve it:
ProcessRunner runner = new ProcessRunner(Path, hSessionToken);
runner.Run();
this.Launch(context);
And in my ProcessRunner class i used something like:
CreateProcessAsUser(this.mSessionTokenHandle, this.mApplicationPath, this.CommandLine, IntPtr.Zero, IntPtr.Zero, 0, creationFlags, envBlock, this.WorkingDirectory, si, pi);
ProcessWaitHandle waitable = new ProcessWaitHandle(pi.hProcess);
if (waitable.WaitOne())
{
return;
}
because WaitOne returns true when it gets signaled.
This is my class to fiddle with the wait handle.
internal class ProcessWaitHandle : WaitHandle
{
public ProcessWaitHandle(IntPtr processHandle)
{
this.SafeWaitHandle = new SafeWaitHandle(processHandle, false);
}
}
Thanks to JeffRSon for the idea to work with the handles.