title: C# Using Shutdown.exe just Shutdown
body: <p>am using Shutdown.exe in my application because it offers some nice features like it can delay a shutdown and add a comment why need to shutdown.</p>
  
  <p>The app specs can Shutdown, Restart, Log-Off, Hibernate, the Hybrid shutdown stuff, add comment, and delay a shutdown, and abort a scheduled shutdown.</p>
  
  <p>The application was nice and dandy and I have made a setup file. I now tried installing it locally and used it. But when I tried for example clicked hybernate, it just shutdown ... I clicked on restart, it shuts down, and same thing with others.</p>
  
  <p>I am pretty sure that I am using the correct combination of paramaters</p>
  
  <p>this is the parameter I used</p>
  
  <pre><code>void PowerButtonsClick(object sender, RoutedEventArgs e)
  {
      string p = string.Empty;
  
      if (sender == btnShutdown)
      {
          p += "-s";
      }
      else if (sender == btnRestart)
      {
          p += "-r";
      }
      else if (sender == btnSignoff)
      {
          p += "-l";
      }
      else if (sender == btnHibernate)
      {
          p += "-h";
      }
      else if (sender == btnHybridShutdown)
      {
          p += "-hybrid -s";
      }
      else if (sender == btnAbortShutdown)
      {
          p += "-a";
      }
  
      if (sender != btnAbortShutdown)
      {
          if (sender != btnSignoff || sender != btnHibernate)
          {
              if (isForced) { p += " -f"; }
  
              double seconds = TimeSpan.FromTicks(timePicker.Value.Value.Subtract(DateTime.Now).Ticks).TotalSeconds;
  
              p += " -t " + Convert.ToInt32(seconds);
  
              if (hasComment)
              {
                  p += string.Format(" -c \"{0}\"", borderComment_txComment.Text);
              }
          }
      }
  
      System.Diagnostics.Debug.WriteLine("param: " + p);
  
      System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo()
      {
          Arguments = p,
          FileName = "shutdown.exe"
      });
  }
  </code></pre>
  
  <p>and this is the application I created 3 days ago. It was meant for Windows 8, and now, I shut off the download link because of the problem
  <a href="http://wall.jaysonragasa.net/wall/post/2012/06/17/Windows-8-System-Power-Shortcuts.aspx" rel="nofollow">http://wall.jaysonragasa.net/wall/post/2012/06/17/Windows-8-System-Power-Shortcuts.aspx</a></p>
  
  <p>to tell you honestly, everything works well when running from IDE.. but when installed .. I had the problem. I even tried to disassemble the deployed application using ILSpy and it looks ok and nothing wrong..</p>
  
  <p>-- UPDATE --
  just to update my code in </p>
  
  <pre><code>if (sender != btnSignoff || sender != btnHibernate) { ~~ }
  </code></pre>
  
  <p>it must be</p>
  
  <pre><code>if (sender != btnSignoff &amp;&amp; sender != btnHibernate) { ~~ }
  </code></pre>
  
  <p>the log result in case you requested</p>
  
  <pre><code>param: -s -f -t 0
  param: -l
  param: -r -f -t 0
  param: -h
  param: -a
  param: -hybrid -s -f -t 0
  param: -s -f -t 0 -c "my comment"
  param: -s -f -t 5 -c "my comment"
  param: -s -f -t 12118 -c "my comment"
  param: -s -t 12110 -c "my comment"
  </code></pre>
  
  <p>-- UPDATE --</p>
  
  <p>I have decided to use API calls but I loose the Abort functionality which is so important. If you can share how to Abort a scheduled shutdown, even if using WMI or API, kindly please share it.</p>
  
  <p>Regards to all</p>