title: How to shut down from C#, Process.Start("shutdown") not working in Windows XP
body: <p>After some poking around on how to reset my computer and or shut it down from C# I found this explanation on how to do that:</p>
  
  <pre><code>ManagementBaseObject outParameters = null;
  ManagementClass sysOS = new ManagementClass("Win32_OperatingSystem");
  sysOS.Get();
  
  // Enables required security privilege.
  sysOS.Scope.Options.EnablePrivileges = true;
  
  // Get our in parameters
  ManagementBaseObject inParameters = sysOS.GetMethodParameters("Win32Shutdown");
  
  // Pass the flag of 0 = System Shutdown
  inParameters["Flags"] = "1"; //shut down.
  inParameters["Reserved"] = "0";
  foreach (ManagementObject manObj in sysOS.GetInstances())
  {
      outParameters = manObj.InvokeMethod("Win32Shutdown", inParameters, null);
  }
  </code></pre>
  
  <p>This worked in Windows&nbsp;7, but not on the Windows&nbsp;XP box I tried it on. So I figured well lets go with a simpler solution:</p>
  
  <pre><code>Process.Start("shutdown", "/s /t 00");
  </code></pre>
  
  <p>Alas that as well seems to work on my windows 7 box, but not my Windows&nbsp;XP  box.  I have only tried it on one Windows&nbsp;XP  machine, but it flashes up like a command prompt, my program that is up is minimized to the system tray and then nothing happens..so its like it wants to do something but ultimately nothing happens. (I do have code that purposely puts my program to the sys tray when the close X is hit, and the user has to purposely exit it... )  is there an issue with that? My FormClosing code is this:</p>
  
  <pre><code>private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
  {
      if (!canExit)
      {
          e.Cancel = true;
          this.WindowState = FormWindowState.Minimized;
      }
      else
      {
          // Write out the logs.
          List&lt;String&gt; logs = LogUtil.getLog(); // mic.getLog();
  
          // Create a writer and open the file
          TextWriter tw = new StreamWriter(userAppData + "\\logTMC.txt", true);
  
          // Write a line of text to the file
          tw.WriteLine("----- " + DateTime.Now + " ------");
          foreach (String log in logs)
          {
              tw.WriteLine(log);
          }
  
          // Close the stream
          tw.Close();
      }
  }
  </code></pre>
  
  <p>I am not sure why I can reset, and shutdown my pc from C# in Windows&nbsp;7, but not on Windows&nbsp;XP...maybe I missed something? An extra command? A better way to close out the log file I have open when the form closes? Some way to force a shutdown or reset no matter what, the Windows&nbsp;XP box I am using does indeed have an SVN server as a windows service running, but I am not sure if this makes a difference or not.</p>
  
  <p>So I am not really sure where to investigate my problem. Does the <code>Process.Start()</code> have a way to see a return or a try catch to see what might of caused it not to shut down or is it a "fire and forget" type a deal?</p>