I am developing a windows service in .Net 3.5 开发者_StackOverflow中文版in C#. This service is used to periodically invoke a windows form. Now I would like to hook an event to the service so that when the user tries to shut down the system, then also the windows form will appear, preventing the shut down process. User can then only make the system shutdown through the windows application.
Is there a way to do this in a windows service?
Edit
I want this to be done in Win 2000 and Win XP only.
Thanks
Services should not interact with the user session. In Vista and Win7 this is actually prohibited. The proper way to interact with the user session is to have an application in the session that communicates with the service, so your approach to create a service that starts periodically a form is flawed. Preventing system shutdown sounds just as bad, and again Win7 will just overwrite your application with a dim screen suggesting the user to kill the vandal (that is the misbehaving appp, yours).
Legitimate applications that alter the user experience the way you suggest have proper APIs to do so, like shell replacements for example.
精彩评论