I am trying to make a service that spawns a desktop application, and then watches to make sure it restarts again if it is closed. .
I would like it to basically spawn the process and then forget about it, allowing to act like a normal interactive application. (Apparently this is much easier to do in XP and before, but I need this for XP, Vista, and 7)
My problem now is that either it shows up invisible if I use process.start() with desktop interactive checked, and if I directly spawn a form it asks “Do you REALLY want to do this?!” and then the whole screen goes blank EXCEPT for my program.
I just want this to be an inoffensive background app. I have the app working well, I just need to figure out how to spawn it from a service without all the trouble.
I am finding all of this stuff that says “Don’t make services that have UI”, but first off this was a requirement that was given to me. (Boss does not want it to be a scheduled task) Also, I noticed that the Task scheduler is itself a service, and it does not have any problem spawning user interactive applications. Why can’t I do that too?
What am I doing wrong?
UPDATE:
Thanks for all the useful info. Was able to convince my boss that this wasn’t possible to achieve based on the session 0 isolation, so I marked that one as the answer and gave upvotes to everyone who gave useful info. Thanks again! 🙂
As of Windows Vista (and consequently Windows 7), services cannot directly interact with the user/desktop for security reasons. Dialogs and other forms that are spawned from a service are shown in Session 0 while your users are logged into Session 1. For more on this, read the Session 0 Isolation section here. In short, calling
Process.Start()from a Windows service on Windows 7 is going to cause issues.You can still interact with the user. You just have to do so indirectly, as described here. I hope that points you in the right direction.