Skip to content

Instantly share code, notes, and snippets.

@mjfusa
Created November 19, 2019 01:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mjfusa/6935cf8b38a9330ef54b7b899c3dedaf to your computer and use it in GitHub Desktop.
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