[英]C# - Check if a UWP app is installed on Windows10
Question : Using C#
how can we check if a UWP
application is installed on Windows
10`问题:使用
C#
如何检查Windows
10 上是否安装了UWP
应用程序
Possible Goal : My real motivation is to develop an MS Office app in VS2017
using Microsoft.Office.Interop that interacts with a UWP app like this one explained here .可能的目标:我的真正动机是为了开发在微软Office应用程序
VS2017
使用Microsoft.Office.Interop与像UWP应用程序交互这一解释在这里。 But the office app would first check if the required UWP app is installed or not.但是办公应用程序会首先检查是否安装了所需的 UWP 应用程序。
For the old Windows 32bit and 64bit apps, we could check if an application is installed using various methods such as the following.对于旧的 Windows 32 位和 64 位应用程序,我们可以使用以下各种方法检查是否安装了应用程序。 I was wondering if there is something similar for UWP on Windows 10:
我想知道 Windows 10 上的 UWP 是否有类似的东西:
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
语句来调用它:
if (IsSoftwareInstalled("OpenSSL"))
You can call the PackageManager.FindPackageForUser API from the Win32 app to check if the UWP is installed for the current user. 您可以从Win32应用程序调用PackageManager.FindPackageForUser API,以检查是否为当前用户安装了UWP。
https://docs.microsoft.com/en-us/uwp/api/windows.management.deployment.packagemanager.findpackageforuser https://docs.microsoft.com/en-us/uwp/api/windows.management.deployment.packagemanager.findpackageforuser
as I didn't have access to the UWP PackageManager
api I actually just did a simple directory check由于我无权访问 UWP
PackageManager
api 我实际上只是做了一个简单的目录检查
var appPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Packages", "YourAppId");
if (Directory.Exists(appPath))
{
//exists
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.