如何确定现有应用的安装范围? [英] How to determine install scope of existing app?
问题描述
我有一个基于 WixUI_Advanced
的安装程序,允许用户选择他们的安装范围(每个用户或机器范围).
I have an installer based on the WixUI_Advanced
that allows users to choose their install scope (per user or machine wide).
升级时(安装了较低版本的现有应用)我想隐藏安装范围屏幕并自动选择他们上次选择的安装范围.
When upgrading (have an existing app with a lower version installed) I would like to hide the install scope screen and automatically select the install scope they chose last time.
如何知道上次安装使用了哪个安装范围?
How can I tell what install scope was used for the previous installation?
编辑
查看我的 MSI 日志,我可以看到找到了我现有的安装:
Looking at my MSI logs I can see that my existing installation is found:
// Existing user specific installation
FindRelatedProducts: Found application: {C5D3DCD0-4A97-4224-AF22-BDDEB357EEB7}
MSI (c) (C4:F0) [11:11:39:289]: PROPERTY CHANGE: Adding WIX_UPGRADE_DETECTED property. Its value is '{C5D3DCD0-4A97-4224-AF22-BDDEB357EEB7}'.
MSI (c) (C4:F0) [11:11:39:289]: PROPERTY CHANGE: Adding MIGRATE property. Its value is '{C5D3DCD0-4A97-4224-AF22-BDDEB357EEB7}'.
// Existing machine wide installation
MSI (c) (2C:4C) [11:03:19:258]: FindRelatedProducts: current install is per-user. Related install for product '{C5D3DCD0-4A97-4224-AF22-BDDEB357EEB7}' is per-machine. Skipping...
我可以看到 WIX_UPGRADE_DETECTED
和 MIGRATE
属性仅在现有安装的范围与当前安装匹配时才设置,这是有意义的.也许我可以直接使用 FindRelatedProducts
?
I can see the WIX_UPGRADE_DETECTED
and MIGRATE
properties are set only when the existing installation's scope matches the current installation which makes sense. Perhaps I can use FindRelatedProducts
directly?
推荐答案
我最终在注册表中检查了 DisplayName
与我们的应用程序名称匹配的条目(灵感来自 这个答案):
I ended up checking for an entry with the DisplayName
matching our app name in the registry in (inspired by this answer):
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
然后我抓取InstallLocation
的内容来确定安装范围:
Then I grabbed the content of InstallLocation
to determine the install scope:
if (installLocation == string.Empty)
{
// Installed before we introduced scope => never set install location
return ExistingInstallation.MachineWide;
}
else if (installLocation.Contains(_programFilesPath))
{
return ExistingInstallation.MachineWide;
}
else
{
return ExistingInstallation.UserSpecific;
}
这篇关于如何确定现有应用的安装范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!