title: C# Cancel Windows Shutdown
body: <p>i want to my application can prevents from windows shut down. i know that there is a system command to do that. but don't work for my program.
  i use this code for "cancel" the windows shut down:</p>
  
  <pre><code>private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  {
      if (e.CloseReason.Equals(CloseReason.WindowsShutDown))
      {
          MessageBox.Show("Cancelling Windows shutdown");
          string cmd = "shutdown /a";
          Process.Start(cmd);// for executing system command.
      }
  }
  </code></pre>
  
  <p>and also use this code, but does not work :( :</p>
  
  <pre><code>public Form1()
  {
      InitializeComponent();
  
      SystemEvents.SessionEnding += SessionEndingEvtHandler;
  }
  
  private void SessionEndingEvtHandler(object sender, SessionEndingEventArgs e)
  {
      MessageBox.Show("Cancelling Windows shutdown");
      string cmd = "shutdown /a";
      Process.Start(cmd);// for executing system command.  
  }
  </code></pre>
  
  <p>i would be grateful if anyone explain me how can in "cancel" windows shutdown.
  thanks </p>