title: How to enumerate the installed StoreApps and their ID in Windows 8 and 10
body: <p>What I want to get is the AppUserModelId of all installed StoreApp applications, so that I can pass it to <code>IApplicationActivationManager-&gt;ActivateApplication</code>.</p>
  
  <p>In Windows 8 it was stored in the Registry, but in Windows 10 it is not anymore.</p>
  
  <p>There are a lot of questions about this in internet but even after days of searching I could not find a satisfying solution.</p>
  
  <p>What I have so far is the following:</p>
  
  <ol>
  <li>I create an instance of <code>IPackageManager</code>,</li>
  <li>I call <code>FindPackagesByUserSecurityId()</code> with the SID of the current user,</li>
  <li>I iterate through the returned collection</li>
  <li>I get an <code>IPackage</code> interface</li>
  <li>From that I get an <code>IPackageId</code> interface,</li>
  <li>Then I call <code>IPackageId-&gt;get_FamilyName()</code></li>
  </ol>
  
  <p>With that I have for example on Windows 10 for the Windows Calculator the string "<code>Microsoft.WindowsCalculator_8wekyb3d8bbwe</code>".</p>
  
  <p>When I append to this string an "<code>!App</code>" I have the complete AppUserModelId to start the Windows Calculator: "<strong><code>Microsoft.WindowsCalculator_8wekyb3d8bbwe!App</code></strong>"</p>
  
  <p>But not all applications use an "<code>!App</code>" behind the FamilyName.
  For example Spartan uses the AppUserModelId
  "<strong><code>Microsoft.Windows.Spartan_cw5n1h2txyewy!Microsoft.Spartan.Spartan</code></strong>" which does not end with "<code>!App</code>". And when I replace "<code>!Microsoft.Spartan.Spartan</code>" with "<code>!App</code>" it will not start -> "This app does not support the contract specified".</p>
  
  <p>So my question is where do I get the last missing part from?</p>
  
  <p>I found a PowerShell code in internet (<a href="http://poshcode.org/5702" rel="nofollow">http://poshcode.org/5702</a>) that seems to do something very similar:</p>
  
  <pre><code>Get-AppXPackage $PackageName -pv Package |
      Get-AppxPackageManifest | % {
          foreach($Application in $_.Package.Applications.Application) {
              if($Application.Id -like $AppId) {
                  if($Protocol -and !($Application.Extensions.Extension.Protocol.Name | ? { ($_ + "://") -match (($Protocol -replace '\*','.*') + "(://)?") })) {
                      continue
                  }
  
                  [PSCustomObject]@{
                      # Notice the secret magic property:
                      PSTypeName = "Microsoft.Windows.Appx.Application"
                      AppUserModelId = $Package.PackageFamilyName + "!" + $Application.Id
                  }
              }
          }
      }
  </code></pre>
  
  <p>I really don't understand this cryptic PowerShell stuff, but one line seems interesting to me:</p>
  
  <pre><code>foreach($Application in $_.Package.Applications.Application)
  </code></pre>
  
  <p>This seems to enumerate Applications in a Package.</p>
  
  <p>A comment in the same PowerShell code says:</p>
  
  <pre><code># The full AppUserModelId is composed of the package name, 
  the publisher id, and the app id, such as
  Microsoft.ZuneMusic_8wekyb3d8bbwe!Microsoft.ZuneMusic
  </code></pre>
  
  <p>so what is missing is the <code>$Application.Id</code>.</p>
  
  <p>If I could get an <code>IAppInfo</code> interface anyhow I could call <code>IAppInfo-&gt;get_Id()</code> and I would be ready.</p>
  
  <p>But I don't know how to get this from an <code>IPackage</code> in C++.</p>