C#: How can I detect instantlly Shutdown or Logout?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi everyone.
Ive been searching for detecting when Windows XP start to shutdown or logoff.


What I want to do:
  Bring a window (my form) and ask if you want to continue closing (shutdown or logoff); if not, return to windows.
But the PROBLEM is that other programs close first! before my application detects the closing (shutdown).

What Ive done for detection:
  1. Override the WndProc inside the form and ask m.Msg == WM_QUERYENDSESSION.
  2. On Form closing event ask e.CloseReason == CloseReason.WindowsShutDown.
  3. SystemEvents.SessionEnding event works but just when my app has been focus to be close by the shutdown. It still close other programs before mine asks.
  - I use the command "shutdown -a" for stopping from shutdown.


Please help me. I dont know "hooks" but it seems that i need them for detecting at real time, just exactly when the shutdown has started. I either dont know services but i dont know if you can show a window this way.

Thank you very much.



View the full article
 
Back
Top