Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if Windows Store is available

My goal is to suggest users to install the Store version of the app from the desktop app, but I need to know if the user can do it (e.g. its Windows 10+, and store is available).

I can easily detect Windows 10+.

The problem is that there are many SKUs like Windows Server and Windows LTSB, which do not have the Store, but provide essentially the same APIs.

What I've tried so far:

  • try create an instance of Windows.Management.Deployment.PackageManager
  • the GetProductInfo function

The former succeeded on Windows Server, despite the lack of the Store.

The latter, while currently being adequate for today, requires checking for all non-Store SKUs manually, and does not really solve the problem, as nothing prevents Microsoft from introducing Windows Store into Windows 2019 LTSB.

Actually, more specifically, I want to know if the current user can install desktop bridge apps from Windows Store.

like image 642
LOST Avatar asked Aug 03 '18 20:08

LOST


People also ask

How do I check Windows Store?

Select Start then enter Microsoft Store. Select it to open the app. If Microsoft Store won't launch, get more info at Microsoft Store does not launch.

How do I know if Microsoft Store is installed?

If the Microsoft Store app isn't on the taskbar, it might have been unpinned. Here's how to search for it: Select Start and enter Microsoft Store. If you see it in the results, select it.

How do I make Microsoft Store available?

Sign in to Microsoft Store for Business or Microsoft Store for Education. Click Manage, and then choose Products and services. Click on the application to open the application settings, then select Private store availability. Select Everyone to make application available for all people in your organization.


1 Answers

You could use the Get-AppxPackage PowerShell command to check whether the Microsoft.StorePurchaseApp package is installed or not.

First, install the System.Management.Automation.dll NuGet package using the Package Manager Console:

PM> Install-Package System.Management.Automation.dll

Then use a method like this:

public static bool IsStoreAvailable()
{
    using (var shell = PowerShell.Create())
    {
        shell.AddScript("Get-AppxPackage -Name Microsoft.StorePurchaseApp");
        var result = shell.Invoke();
        return result.Any();
    }
}
like image 113
huysentruitw Avatar answered Oct 21 '22 07:10

huysentruitw