title: Get path of current active window using window handle
body: <p>I'd like to know how to grab the Path of the current active window using C#.   </p>
  
  <p>i get handle of currnet active window </p>
  
  <pre><code>        const int nChars = 256;
          int handle = 0;
          StringBuilder Buff = new StringBuilder(nChars);
  
          handle = GetForegroundWindow(); 
  </code></pre>
  
  <p>now how do i get path of this window?  </p>
  
  <p>i.e: Path of "my document" window is </p>
  
  <pre><code>C:\Users\User\Documents
  </code></pre>
  
  <p><strong>-=-=-==-=-=edit-=-=-=-=-=-</strong><br>
  i want to wirte program to monitor "windows explorer" and see Where the user goes?<br>
  (i.e:user go to c:\ and then go to program files and then go to Internet Explorer and i want to get this path:C:\Program Files\Internet Explorer.
  <img src="https://i.stack.imgur.com/P4GAv.png" alt="enter image description here">  </p>