title: can't terminate process using WMI but taskkill works
body: <p>My user is in the Administrators group.  I am using the .NET WMI API (System.Management) to kill a process using this code:</p>
  
  <pre><code>var scope = new ManagementScope("\root\cimv2");
  scope.Connect();
  var query = new ObjectQuery(
      string.Format("Select * from Win32_Process Where ProcessID = {0}",
          processId));
  var searcher = new ManagementObjectSearcher(scope, query);
  var coll = searcher.Get().GetEnumerator();
  coll.MoveNext();
  var mgmtObj = (ManagementObject)coll.Current;
  var ret = (uint) mgmtObj.InvokeMethod("Terminate");
  // ret == 2 here, meaning "Access Denied"
  </code></pre>
  
  <p>It's failing to kill the process and returning a <code>2</code> (<code>Access Denied</code>).  However if I use:</p>
  
  <pre><code>Process.Start("cmd", string.Format("/c \"taskkill /f /pid {0}\"", processId));
  </code></pre>
  
  <p>the process gets killed.  (but if I leave out <code>/f</code> it fails).</p>
  
  <p>Is there any way to terminate the process using WMI?</p>
  
  <p><strong>EDIT:</strong> I found the following on
  <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa393907(v=vs.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/desktop/aa393907(v=vs.85).aspx</a>:</p>
  
  <blockquote>
    <p>To terminate a process that you do not own, enable the
    SeDebugPrivilege privilege.</p>
  </blockquote>
  
  <p>The page provides VBScript code but how would I do this in C#?</p>