How to detect if a Microsoft Store app is Installed

Microsoft store logo

There may be times when you need to determine if a Microsoft Store app has been installed. You may have a dependency on that app or otherwise need to take action based on the presence of that app.

FindPackageForUser

The API PackageManager.FindPackageForUser() can do this. See the code below. Note the special handling for the various error conditions. This API returns a Package object if the app is installed for the current user. The API will throw an Access denied exception if 1) the app is not installed on the machine or 2) it is on the machine but not installed for the current user. The API will throw an Argument exception if the string for the package family name is not in the correct format.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
public static bool IsAppAlreadyInstalled(string FullPackageFamilyName)
{
    var oPkgManager = new PackageManager();
    bool result = false;
    try
    {
        //If 1st parameter is string.Empty, the packages are retrieved for the current user.
        Package oPkg = oPkgManager.FindPackageForUser(string.Empty, FullPackageFamilyName);
        result = oPkg != null;
    }
    catch (ArgumentException syse)
    {
        Debug.WriteLine("Parameter Exception: Check Package full name argument for correct pattern. X.a_N.X.X.0x64__N");
        return result;
    }
    catch (UnauthorizedAccessException syse)
    {
        if (!string.IsNullOrEmpty(syse.Message))
        {
            if (syse.Message.IndexOf("Access is denied", StringComparison.CurrentCulture) >= 0)
            {
                Debug.WriteLine("Access denied");
                return result;
            }
        }
    }
    catch (Exception ex)
    {
        if (!string.IsNullOrEmpty(ex.Message))
            Debug.WriteLine(@"Exception: {0}", ex.Message);
        return result;
    }
    return result;
}

private void Button_Click(object sender, RoutedEventArgs e)
{
    // Sample code: This should return 'access denied' since this will not exist on your machine
    var res = IsAppAlreadyInstalled("57012MikeFrancis.TrialTest123_1.66.5.0_x64__08pddan6qgabc");
}

Full App Package Name

You need the full package name to call FindPackageForUser(). To get a list of all of the packages currently installed, you can use the PowerShell command Get-AppxPackage.

getappxpackage

For the Microsoft Store apps that you have published, you can get the full package family name from the App Identity page in Partner Center. See screenshot below.

app identity

Please let me how this method works for you or if you have another solution for determining the installation status of an app on Windows 10.

The code is available here.

@MikeFrancis

Licensed under CC BY-NC-SA 4.0
comments powered by Disqus