Prevent windows Shutdown with CANCEL option C#

青春壹個敷衍的年華 提交于 2019-12-07 00:37:31
   private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (e.CloseReason.Equals(CloseReason.WindowsShutDown))
        {
           if (MessageBox.Show("You are closing this app.\n\nAre you sure you wish to exit ?", "Warning: Not Submitted", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Stop) == DialogResult.Yes)
               return;    
           else    
               e.Cancel = true;
        }
    }

Although delay windows shutdown is not recommended it is possible using shutdown scripts. You can configure your own script file using gpedit.msc configuration file. I have read that these scripts can delay the windows shutdown up to 10 minutes.

I hope it helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!