title: How to get active window app name as shown in task manager
body: <p>I am trying to get the active window's name as shown in the task manager app list (using c#).
  I had the same issue as described <a href="https://stackoverflow.com/questions/14540118/how-to-get-name-of-active-window">here</a>.
  I tried to do as they described but I have issue while the focused application is the picture library I get exception.
  I also tried <a href="https://stackoverflow.com/questions/277085/how-do-i-getmodulefilename-if-i-only-have-a-window-handle-hwnd/321343#321343">this</a>, but nothing gives me the results I expect.
  For now I use:</p>
  
  <pre><code>IntPtr handle = IntPtr.Zero;
  handle = GetForegroundWindow();
  
  const int nChars = 256;
  StringBuilder Buff = new StringBuilder(nChars);
  if (GetWindowText(handle, Buff, nChars) &gt; 0)
  {
      windowText = Buff.ToString();
  }
  </code></pre>
  
  <p>and delete what is not relevant based on a table I created for most common apps, but I don't like this workaround.
  Is there a way to get the app name as it is in the task manager for all running app?</p>