Yeah! Figured out how to get informed about the windows system shutdown/user logged off in .NET. With the knowledge of my VB6 days (there we get the info as a parameter in the window close event) my research goes completely to the wrong direction and a search via google does not point to a similar solution for .NET.
The may be simplest code to use is this:
public class Form1: System.Windows.Forms.Form {
// Constant value was found in the "winuser.h" header file.
private const int WM_ENDSESSION = 0x0016;
...
protected override void WndProc(ref Message m) {
switch (m.Msg) {
case WM_ENDSESSION:
// Save settings, state whatever here... MessageBox.Show("WM_ENDSESSION received."); Application.Exit(); // exit the normal way break; // never reached
}
base.WndProc(ref m);
}
...
}