I want to be able to intercept the shutdown event in C# for Windows Vista. Due to the advanced security features with Vista, any applications that are running after the shutdown command is called are halted and displayed in a list, prompting the user to do something with them.
Does anybody know how to overcome this and what events I need to be using in Vista.
Thanks.
You can use WPF's application object and subscribe to its SessionEnding event. You can then look at the SessionEndingCancelEventArgs.ReasonSessionEnding enumeration to determine exactly why the session is ending (LogOff or Shutdown).
What you may want to look at is here - Application Shutdown Changes in Windows Vista. Basically, for what you want, it all revolves around WM_QUERYENDSESSION.
Note that this is exposed in the .net framework - instead you will need to use native functions (p/invoke) and hook the wndproc in your code to respond to the windows message.
For an example (showing a reason to not shutdown), you can see Windows Vista - ShutdownBlockReasonCreate in C#.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With