阻止系统关机

C#阻止系统关机,重启,注销

C#拦截关机

C#禁止关机

 protected override void WndProc(ref System.Windows.Forms.Message m)
{
    if (m.Msg == 0x11)//WM_QUERYENDSESSION 
    {
        m.Result = (IntPtr)0;//0不关闭程序和系统;1关闭程序及系统 
        return;
    }
    base.WndProc(ref m);
}

原文地址:https://www.cnblogs.com/linmilove/p/1752411.html