title: InitiateSystemShutdown call not working
body: <p>I'm writing an application that will need to reboot the Windows machine the code is running on.</p>
  
  <p>There didn't appear to be an API within .NET to do this, so I looked up the the Win32 API for this and it is called InitiateSystemShutdown. The extern declaration is given below:</p>
  
  <pre><code>[DllImport("advapi32.dll")]
  public static extern bool InitiateSystemShutdown(string Machinename, string
  Message, long Timeout, int ForceAppsClosed, int RebootAfterShutdown);
  </code></pre>
  
  <p>I then try to call this operating system routine with the following arguments:</p>
  
  <pre><code>InitiateSystemShutdown(null, null, 30, 1, 1);
  </code></pre>
  
  <p>However, this always returns false. So I call the Marshal.GetLastWin32Error method and it returns an error code of 1008. This error code's message is: </p>
  
  <p>"An attempt was made to reference a token that does not exist."</p>
  
  <p>The code is running inside a Windows Service and is running under the Administrator account. I've tried running it as Local System and that had not effect.</p>