I'm currently playing with CreateProcessAsUser using P/Invoke from c#, in order to launch process as limited users from a windows Service running in SYSTEM Account.
My objective is to have a Service that launches an app that needs to get info from users on our office (process running in foreground, time idle, etc.). Problem is that if this app is running with user's privilige... well, he can close it. If running like a regular process from another app I can control this respawn with:
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = ExePath;
psi.UseShellExecute = false;
Process p = new Process();
p.StartInfo = psi;
p.EnableRaisingEvents = true;
p.Exited += new EventHandler(LaunchAgain);
p.Start();
But this way, my problem is that instead having a no-respawn-closable-by-user-app, I have two-apps-closable-by-user (well, but one of them respawns the other :P).
Do you know it there is some way of know if a process created by CreateProcessAsUser can be "monitored" to launch some action when it's killed or terminated?
PD: Of course, be free of suggest any kind of improve or different approaches.