How to prevent users from using my UWP app after the trial period ends?

Henry-6115 41 Reputation points
2023-05-05T04:23:37.67+00:00

I published a UWP app on Microsoft Store. It is a paid app, but it offers a one-day free trial.

I found that some users can still use my app after the trial period ends, without paying for it.

I thought Windows should prevent them from opening the app, just like some free trial apps I downloaded myself.

Why is this happening? Do I need to add some logic in my code to check the license status?

Microsoft Partner Center
Microsoft Partner Center
A Microsoft website for partners that provides access to product support, a partner community, and other partner services.
669 questions
0 comments No comments
{count} votes

Accepted answer
  1. Roy Li - MSFT 29,356 Reputation points Microsoft Vendor
    2023-05-05T06:21:20.7+00:00

    Hello,

    Welcome to Microsoft Q&A!

    First of all, If the trial expires before the user launches the app, your app won't launch. Instead, users see a dialog box that gives them the option to purchase your app from the Store.

    A possible reason for this is that A user brougth your app in the device and now B user has logged in the device and he will be able to use the app in full version.

    I'd suggest you to wrtie your own logic to check the trial license in your app.

    private StoreContext context = null;
    private StoreAppLicense appLicense = null;
    
    // Call this while your app is initializing.
    private async void InitializeLicense()
    {
        if (context == null)
        {
            context = StoreContext.GetDefault();
            // If your app is a desktop app that uses the Desktop Bridge, you
            // may need additional code to configure the StoreContext object.
            // For more info, see https://aka.ms/storecontext-for-desktop.
        }
    
        workingProgressRing.IsActive = true;
        appLicense = await context.GetAppLicenseAsync();
        workingProgressRing.IsActive = false;
    
        // Register for the licenced changed event.
        context.OfflineLicensesChanged += context_OfflineLicensesChanged;
    }
    
    private async void context_OfflineLicensesChanged(StoreContext sender, object args)
    {
        // Reload the license.
        workingProgressRing.IsActive = true;
        appLicense = await context.GetAppLicenseAsync();
        workingProgressRing.IsActive = false;
    
        if (appLicense.IsActive)
        {
            if (appLicense.IsTrial)
            {
                textBlock.Text = $"This is the trial version. Expiration date: {appLicense.ExpirationDate}";
    
                // Show the features that are available during trial only.
            }
            else
            {
                // Show the features that are available only with a full license.
            }
        }
    }
    
    

    More information here: Guidelines for implementing a trial version

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Henry-6115 41 Reputation points
    2023-05-05T04:53:29.27+00:00

    Sorry, I accidentally posted some duplicate posts on the forum, because of a network issue. I want to delete them, but I don’t know how.

    0 comments No comments