Cancel shutdown of the computer


There are various ways where for shutting down computer . With the help of this article I explain about how to Cancel shutdown of the computer

The following code shows how to cancel the shutdown process during the running of your application. You may put this code in your application main form's closing event.

When the system is shutting down, windows will try to close your application and you will receive the Form Closing event. If the CloseReason is CloseReason.WindowsShutDown, then you can set it to Cancel which will prevent shutting down windows by anybody.

								
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason.Equals(CloseReason.WindowsShutDown))
{
Microsoft.VisualBasic.Interaction.Shell("shutdown -a", AppWinStyle.MinimizedFocus, false, -1);
MessageBox.Show("Shutdown process cancelled!");
}
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: