Catching Windows Vista Shutdown Events in C #

I want to be able to capture the shutdown event in C # for Windows Vista. Due to the enhanced security features with Vista, all applications that start after the command is turned off stop and appear in the list, prompting the user to do something with them.

Does anyone know how to overcome this and what events I need to use in Vista.

Thanks.

+7
c # windows events windows-vista
source share
5 answers

You can use the WPF application object and subscribe to its SessionEnding event. You can then look at the SessionEndingCancelEventArgs.ReasonSessionEnding enumeration to determine exactly why the session ends (LogOff or Shutdown).

+6
source share

What you can see here - Disabling applications in Windows Vista . Basically, for what you want it all revolves around WM_QUERYENDSESSION.

Please note that this is revealed in the .net framework - instead, you will need to use your own functions (p / invoke) and connect wndproc in the code to respond to the Windows message.

For an example (showing the reason for not shutting down) you can see Windows Vista - ShutdownBlockReasonCreate in C # .

+5
source share
System.Environment.HasShutdownStarted 
0
source share

Use event

Application.SessionEnding for WPF.

0
source share

SessionEnding / SessionEnded events in Microsoft.Win32.SystemEvents may be what you are looking for.

0
source share

All Articles