Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Detect if MS Store app is installed
// Companion to: https://blog.mjfnet.com/2019/11/15/How-to-detect-if-a-Microsoft-Store-app-is-Installed/
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");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.