title: Killing processes with psutil
body: <p>I'm looking to write some code that will kill off a process based on it's name and who owns it. This works fine on Windows XP but when I come to run the same code on Windows 7 I get Access Denied errors when trying to get the username of the process.</p>
  <p>Is there an easier way to kill a process that will work on XP and Win7?</p>
  <p>The check to see if the process is owned by the 'SYSTEM' is actually needed so I can check when the process has user processes are finished, as the SYSTEM process remains, and I'm not concerned with this one.</p>
  <pre><code>PROCNAME = 'python.exe'
  for proc in psutil.process_iter():
    if proc.name == PROCNAME:
      p = psutil.Process(proc.pid)
    
      if not 'SYSTEM' in p.username:
        proc.kill()
  </code></pre>