title: System.Management.ManagementException: "Privilege not held." When trying to Shutdown Windows 7 in C# 4.0 using WMI
body: <p>I have a program with some legacy code that does the following to shutdown windows:</p>
  
  <pre><code>ManagementClass mc = new ManagementClass( "Win32_OperatingSystem" );
  
  mc.Get();
  
  mc.Scope.Options.EnablePrivileges = true;
  ManagementBaseObject mboShutdown = mc.GetMethodParameters( "Win32Shutdown" );
  
  mboShutdown["Flags"] = "5"; // shutdown + force
  mboShutdown["Reserved"] = "0";
  
  foreach( ManagementObject mbo in mc.GetInstances() )
  {
      mbo.InvokeMethod( "Win32Shutdown", mboShutdown, null );
  }
  </code></pre>
  
  <p>It was a .NET 3.5 application, and it was working without a problem.  Recently, a dependency upgrade required bumping the target framework to 4.0 client profile.  Now, whenever the code runs, I am getting the following exception:</p>
  
  <pre><code>System.Management.ManagementException: "Privilege not held."
  </code></pre>
  
  <p>The application is running under an Admin account on Windows 7, and nothing has changed other than updating this software.  </p>
  
  <p>The only information I have been able to find while searching for a solution was some very old bug reports about .NET 1.1, and the following thread on msdn that was never answered:
  <a href="http://social.msdn.microsoft.com/Forums/vstudio/en-US/fa0bcae5-6f30-42b6-bb5f-b8a6edb88ac4/encountered-privillege-not-held-exception-when-rebooting-the-server-in-net40-framewrk" rel="nofollow">http://social.msdn.microsoft.com/Forums/vstudio/en-US/fa0bcae5-6f30-42b6-bb5f-b8a6edb88ac4/encountered-privillege-not-held-exception-when-rebooting-the-server-in-net40-framewrk</a></p>
  
  <p>Does anyone know what the cause of this issue is?  Do I need to stop using WMI and just PInvoke InitiateSystemShutdownEx or something similar?</p>