Intercepting a Logoff
-
I am writing a tiny app which will be triggered in GPO by a user logoff. The app simply checks that the user has done some required housework. Can anyone show me how to interrupt the logoff (and remain logged on) depending on the answer?
Best you can do is handle the SystemEvents.SessionEnding Event (Microsoft.Win32) | Microsoft Docs[^] - it catches both shutdown and logoff. It's cancelable, so your app can request that the system remains up - but it's only a request, it mayu not be honoured depending on what the system is doing. As the documentation says
Quote:
It provides no guarantee that the session will not end.
And it won't detect and cancel a user pulling the plug out of the wall ... :laugh:
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
Best you can do is handle the SystemEvents.SessionEnding Event (Microsoft.Win32) | Microsoft Docs[^] - it catches both shutdown and logoff. It's cancelable, so your app can request that the system remains up - but it's only a request, it mayu not be honoured depending on what the system is doing. As the documentation says
Quote:
It provides no guarantee that the session will not end.
And it won't detect and cancel a user pulling the plug out of the wall ... :laugh:
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
Thanks, I'll look at that. Also found this: https://bytes.com/topic/c-sharp/answers/590618-preventing-logoff-shutdown-until-c-windows-app-closed)
-
Thanks, I'll look at that. Also found this: https://bytes.com/topic/c-sharp/answers/590618-preventing-logoff-shutdown-until-c-windows-app-closed)
There is no way to absolutely prevent a user from logging off or shutting down the system. Even the solution you found is a "suggestion" that the system not shutdown. There is nothing you can do to prevent it as everything you come up with can be defeated just by ending the process that is your application.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
There is no way to absolutely prevent a user from logging off or shutting down the system. Even the solution you found is a "suggestion" that the system not shutdown. There is nothing you can do to prevent it as everything you come up with can be defeated just by ending the process that is your application.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak