How to detect Windows shutdown or logoff

Viewed 61272
3 Answers

Now you should use something like this:

private static int WM_QUERYENDSESSION = 0x11;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
    if (m.Msg==WM_QUERYENDSESSION)
    {
        MessageBox.Show("queryendsession: this is a logoff, shutdown, or reboot");
    }
    
    base.WndProc(ref m);
}
Related