title: How do I (administrator) gracefully close a window process running in another user session using powershell on Windows 2008 R2 Remote Desktop Services
body: <p>If I run the following command in my session...</p>
  
  <pre><code>(Get-Process -Id $pid).CloseMainWindow()
  </code></pre>
  
  <p>I am able to gracefully shut down a process (no modal windows or other popups arise).  </p>
  
  <p>If, however, the pid is in another user's session on the same machine (running RDS), the process does not close, and CloseMainWindow() returns FALSE (it returns TRUE if it's running in my own session).  It also works if I run the powershell from the other user's session.</p>
  
  <p>I specifically need a way to <em>gracefully</em> shut down the program as the program has a few important cleanup actions required to keep its database in order.  So stop-process or process.kill() will not work.</p>