C# - Check if a UWP app is installed on Windows10

情到浓时终转凉″ 提交于 2019-12-11 09:36:17

问题


Question: Using C# how can we check if a UWP application is installed on Windows10`

Possible Goal: My real motivation is to develop an MS Office app in VS2017using Microsoft.Office.Interop that interacts with a UWP app like this one explained here. But the office app would first check if the required UWP app is installed or not.

For the old Windows 32bit and 64bit apps, we could check if an application is installed using various methods such as the following. I was wondering if there is something similar for UWP on Windows 10:

private static bool IsSoftwareInstalled(string softwareName)
{
    var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall") ??
              Registry.LocalMachine.OpenSubKey(
                  @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall");

    if (key == null)
        return false;

    return key.GetSubKeyNames()
        .Select(keyName => key.OpenSubKey(keyName))
        .Select(subkey => subkey.GetValue("DisplayName") as string)
        .Any(displayName => displayName != null && displayName.Contains(softwareName));
}

Then use an if statement to call it:

if (IsSoftwareInstalled("OpenSSL"))

回答1:


You can call the PackageManager.FindPackageForUser API from the Win32 app to check if the UWP is installed for the current user.

https://docs.microsoft.com/en-us/uwp/api/windows.management.deployment.packagemanager.findpackageforuser




回答2:


as I didn't have access to the UWP PackageManager api I actually just did a simple directory check

var appPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Packages", "YourAppId");            

if (Directory.Exists(appPath))
{
    //exists
 }


来源:https://stackoverflow.com/questions/54369640/c-sharp-check-if-a-uwp-app-is-installed-on-windows10

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!