title: Get path of a Metro (Modern UI) app on Windows 8/8.1
body: <p>How do I get the path of the foreground metro app on Windows <strong>8</strong> and Windows <strong>8.1</strong> using WINAPI?</p>
  
  <p>For example if the foreground app is 'Weather' then the app-specific path that I'm looking for is:</p>
  
  <blockquote>
    <p>C:\Program Files\WindowsApps\Microsoft.BingWeather_2.0.0.310_x64__8wekyb3d8bbwe</p>
  </blockquote>
  
  <p>This information is shown in the Task Manager if you right-click properties on an app. However I want too retrieve it programmatically using WINAPI.</p>
  
  <p>I tried using <code>GetForegroundWindow</code>, <code>GetWindowThreadProcessId</code> and <code>QueryFullProcessImageName</code> but this only returns the path of the WWAHost container process ("C:\Windows\System32\WWAHost.exe") instead of the app-specific path described above.</p>
  
  <p>Windows 10 metro apps also run in a container however one of the child HWND's is owned by an app-specific process. By searching for this HWND I was able to get the app-specific path on Windows 10. However on Windows 8/8.1 there are only 3 HWNDs and they are all owned by the WWAHost container process so this trick didn't work.</p>