简体   繁体   English

如何确定现有应用的安装范围?

[英]How to determine install scope of existing app?

I have an installer based on the WixUI_Advanced that allows users to choose their install scope (per user or machine wide).我有一个基于WixUI_Advanced的安装程序,它允许用户选择他们的安装范围(每个用户或机器范围)。

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?我如何知道上次安装使用了哪个安装范围?


Edit编辑

Looking at my MSI logs I can see that my existing installation is found:查看我的 MSI 日志,我可以看到找到了我现有的安装:

// 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...

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.我可以看到WIX_UPGRADE_DETECTEDMIGRATE属性仅在现有安装的范围与当前安装匹配时才设置,这是有意义的。 Perhaps I can use FindRelatedProducts directly?也许我可以直接使用FindRelatedProducts

This is not a complete answer.这不是一个完整的答案。 I had to add as an answer because of formatting requirements.由于格式要求,我不得不添加作为答案。


UPDATE : Looked at this, ran out of time again.更新:看着这个,又没时间了。 This really is no answer at all, but just lobbing it to you in case it can help you research it yourself . This really is no answer at all, but just lobbing it to you in case it can help you research it yourself

Registry Persistence : I assume you have tried to persist ALLUSERS and / or the installation scope in the registry and read it back in the updated MSI?注册表持久性:我假设您已尝试将ALLUSERS和/或安装范围保留在注册表中并在更新的 MSI 中读回它? I didn't look at that.我没有看那个。 For that to work you have to do it in the first release of the package and keep it up later.为此,您必须在软件包的第一个版本中执行此操作,并在以后继续使用。

MSI API Automation : Here is a little hack to find the previously installed products on the box (this essentially runs similar stuff as "FindRelatedProducts" inside MSI files): MSI API 自动化:这里有一个小技巧,可以在盒子上找到以前安装的产品(这基本上运行与 MSI 文件中的"FindRelatedProducts"类似的东西):

Inside MSI : MSI内部

Set upgrades = Session.installer.RelatedProducts("INSERT-UPGRADE-CODE")
For Each u In upgrades
    scope = Session.installer.ProductInfo(u,"AssignmentType")
    MsgBox CStr(scope)
Next

Standalone, run script directly (install the MSI with the upgrade code specified first):单机,直接运行脚本(先安装指定升级码的MSI):

Set installer = CreateObject("WindowsInstaller.Installer")
Set upgrades = installer.RelatedProducts("INSERT-UPGRADE-CODE")

For Each u In upgrades
   MsgBox "Product Code: " & u & vbNewLine & "Installation Context: " & installer.ProductInfo(u,"AssignmentType")   
Next

MsgBox "Done"

I was thinking to do something like this in the GUI-sequence, but ran out of time again:我想在 GUI 序列中做这样的事情,但又没时间了:

If scope = 1 Then
  Session.Property("ALLUSERS") = "1"
  Session.Property("MSIINSTALLPERUSER") = ""
  Session.Property("WixAppFolder") = "WixPerMachineFolder"
Else
  Session.Property("ALLUSERS") = "2"
  Session.Property("MSIINSTALLPERUSER") = "1"
  Session.Property("WixAppFolder") = "WixPerUserFolder"
End If

WiX Snippets : WiX 片段

<Binary Id='Scope.vbs' SourceFile='Debugging Custom Actions\Scope.vbs' />
<CustomAction Id='Scope.vbs' VBScriptCall='' BinaryKey='Scope.vbs' Execute='immediate' Return='ignore'/>

<..>

<InstallUISequence>
  <Custom Action='Scope.vbs' Before='CostInitialize' />      
</InstallUISequence>

I was going to look at this, but ran out of time.本来想看的,可惜没时间了。 Essentially WIX_UPGRADE_DETECTED will be set in the new setup being installed.基本上WIX_UPGRADE_DETECTED将在正在安装的新设置中设置。 See this answer for more .有关更多信息,请参阅此答案 You could use that property to determine whether to hide or show a button.您可以使用该属性来确定是隐藏还是显示按钮。 I tested that briefly and it worked, but implementing it in WiX is harder.我对此进行了简短的测试并且它起作用了,但是在 WiX 中实现它更难。 You need to override the whole dialog I think.我认为您需要覆盖整个对话框。

In MSI tables, it would be something like this (Orca screenshot - MSI viewer tools ):在 MSI 表中,它会是这样的(Orca 屏幕截图 - MSI 查看器工具):

逆戟鲸


Throwing in some more links:抛出更多链接:

I ended up checking for an entry with the DisplayName matching our app name in the registry in (inspired by this answer ):我最终在注册表中检查了DisplayName与我们的应用程序名称匹配的条目(受此答案启发):

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

Then I grabbed the content of InstallLocation to determine the install scope:然后我抓取了InstallLocation的内容来确定安装范围:

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM