title: Shutdown or Restart Machine In C# and ASP.NET
body: <p>I want to be able to shutdown down or restart the server that my ASP.NET app is running on. The following code works great in debug mode:</p>
  
  <pre><code>Process process = new Process();
  ProcessStartInfo startInfo = new ProcessStartInfo();
  startInfo.FileName = "shutdown";
  startInfo.Arguments = "/r /f /t 0";
  startInfo.UseShellExecute = true;
  startInfo.Verb = "runas";
  process.StartInfo = startInfo;
  process.Start();
  </code></pre>
  
  <p>I have also tried this code, but I receive the following error "The Process object must have the UseShellExecute property set to false in order to start a process as a user":</p>
  
  <pre><code>var info = new ProcessStartInfo("shutdown.exe", "/r /t 0");
          info.UserName = "administrator";
          //A not-so-secure use of SecureString
          var secureString = new SecureString();
          var password = "password";
          foreach (var letter in password)
          {
              secureString.AppendChar(letter);
          }
          info.Password = secureString;
          var restart = new Process();
          restart.StartInfo = info;
          restart.Start();
  </code></pre>
  
  <p>I add the the following to my code:</p>
  
  <pre><code>info.UseShellExecute = false;
  </code></pre>
  
  <p>Then the error "The Process object must have the UseShellExecute property set to false in order to start a process as a user" goes away, but the the code executes like the first block of code</p>
  
  <p>The server will restart when I execute the code in debug mode or if I run the command is cmd. However when I run the app live on the server, it will not restart. I don't receive any error, or pops saying that the server is or is not going to restart. Can some tell me please what I am doing wrong?</p>
  
  <p><strong>UPDATE:</strong> I have added a <code>try-catch</code> and the app never throws an exception. However when I looked up the event logs, I have found the application error event 1000 for shutdown.exe</p>