Skip to content

Interaction of Windows Store fails when running as an escalated process #10538

@alski

Description

@alski

Describe the bug

When running a WinUI3 application as admin via

  <security>
    <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
      <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
    </requestedPrivileges>
  </security>

then calling either of
var result = await context.RequestPurchaseAsync(addOn.StoreId);
or
var result = await addOn.StoreProduct.RequestPurchaseAsync();
results in the windows store dialog closing immediatley after it has opened, without making an AddOn purchase.

Sorry I can't give you a full code example, as that would require my AddOn keys and partner login :-)

            context = StoreContext.GetDefault();
            context.OfflineLicensesChanged += LicensesChanged;
            // Initialize the context with the window handle (HWND).
            var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(window);
            WinRT.Interop.InitializeWithWindow.Initialize(context, hWnd);

  //Note  A StoreProduct that represents a subscription add-on has the type Durable.
  //https://learn.microsoft.com/en-us/uwp/api/windows.services.store.storeproduct.productkind?view=winrt-26100#windows-services-store-storeproduct-productkind
  var response = await context.GetAssociatedStoreProductsAsync(["Durable", "Consumable"]);
  if (response.ExtendedError == null)
  {
      RegionAnalysisSubscription.UpdateProduct(response.Products);
  }

 public void UpdateProduct(IReadOnlyDictionary<string, StoreProduct> products)
 {
     var found = products.Values.FirstOrDefault(p => p.StoreId == StoreId);
     if (found == null)
     {
         return;
     }

     CanPurchase = found != null;
     CanFreeTrial = found != null
             && found.Skus.Any(sku => sku.SubscriptionInfo.HasTrialPeriod);
     StoreProduct = found;
 }

  public async Task<StorePurchaseStatus> Purchase(WindowsStoreAddonViewModel addOn)
  {
      if (addOn.StoreProduct == null)
      {
          throw new InvalidOperationException($"AddOn {addOn.StoreId} is not purchasable");
      }
      var result = await //context.RequestPurchaseAsync(addOn.StoreId);
                         addOn.StoreProduct.RequestPurchaseAsync();
      log.InfoLine($"Purchase of {addOn.StoreProduct.Title}=>{result.Status}");
      if (result.ExtendedError != null)
      {
          log.ErrorLine(result.ExtendedError.ToString());
      }
      await UpdateProducts();
      return result.Status;
  }

Steps to reproduce the bug

Build an application that requires Admin
Register on WIndowsStore
Generate an AddOn
Attempt to buy the AddOn

Expected behavior

I expect the Windows Store dialog not to close immediately and allow purchase

Screenshots

Non elevated
Image

Elevated

20250429-2302-36.0637115.mp4

NuGet package version

WinUI 3 - Windows App SDK 1.7.1: 1.7.250401001

Windows version

Windows Insider Build (xxxxx)

Additional context

Expecting someone to say "Literally costing me money" 😃

Could this be related to the known issues with FileOpen / FileSave dialogs when runnning as Admin?
Trying to use a FileOpenPicker while running the app as Administrator will crash the app #2504

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions