将WIXUI_INSTALLDIR设置为注册表中的值,如果为空,则将其设置为默认值?

时间:2014-04-30 04:00:05

标签: wix

我希望能够从注册表中读取一个值,并在显示对话框之前使用它来设置WIXUI_INSTALLDIR,但如果注册表中的值为空,我想使用默认文件夹。

我是wix的新手。 我整天都在阅读教程,文档和问题/答案,而且我的脑袋在旋转。我觉得我很接近,但我没有把所有的东西放在一起。

代码编译和链接很好但是当我运行msi时,我在显示浏览文件夹对话框之前出现错误,错误是代码2819“对话框[2]上的控件[3]需要链接到它的属性。 “

总之我想做的是:
将以前的安装路径从注册表读入名为“PREVIOUSINSTALLFOLDER”的属性 如果“PREVIOUSINSTALLFOLDER”为空白,请将“WIXUI_INSTALLDIR”设置为“目录”部分中定义的“安装文件夹”。
如果“PREVIOUSINSTALLFOLDER”未空白,请将WIXUI_INSTALLDIR设置为“PREVIOUSINSTALLFOLDER”。

我做错了什么?

谢谢, 埃里克

这是我目前的代码:

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="EB907F6C-B193-4A40-BA3C-ADF8C069AF34" Name="LaserVault DMS" Language="1033" Version="10.0.0" Manufacturer="Electronic Storage Corp." UpgradeCode="43291cbc-3f74-44ba-ba14-31181bb654bf">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" Keywords="LaserVault DMS Server" Description="LaserVault DMS Server" />
    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate EmbedCab="yes" />
<UIRef Id="WixUI_InstallDir"/>

<Property Id="PREVIOUSINSTALLFOLDER">
  <RegistrySearch Id="PreviousInstallDir" Root="HKLM" Key="Software\ESC" Name="LVDMSPath" Type="raw"></RegistrySearch>
</Property>

<CustomAction Id="SetToDefault" Property="WIXUI_INSTALLDIR" Value="[INSTALLFOLDER]" Execute="immediate" />
<CustomAction Id="SetToPrevious" Property="WIXUI_INSTALLDIR" Value="[PREVIOUSINSTALLFOLDER]" Execute="immediate" />

<InstallExecuteSequence>
  <Custom Action="SetToDefault" After="AppSearch">PREVIOUSINSTALLDIR=""</Custom>
  <Custom Action="SetToPrevious" After="AppSearch"><![CDATA[PREVIOUSINSTALLDIR <> ""]]></Custom>
</InstallExecuteSequence>

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="LaserVault" Name="LaserVault">
    <Directory Id="INSTALLFOLDER" Name="LVDMS" />
  </Directory>
  <Directory Id="ProgramMenuFolder" Name="Programs">
    <Directory Id="ProgramMenuDir" Name="LaserVault DMS" />
  </Directory>
  <Directory Id="DesktopFolder" Name="Desktop" />
</Directory>

<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
  <Component Id="LVDMSServerConfig" Guid="D9428A16-ECB1-4373-B876-8CF05E7CE37F">
    <File Id="LVDMSServerConfig" Source="C:\Projects\LVDMS10\LVDMSServerConfig\LVDMSServerConfig\bin\Debug\LVDMSServerConfig.exe" KeyPath="yes" />
  </Component>
  <Component Id="LVDMSCore10" Guid="2E956300-78FC-4AFA-8D5D-A2D07B6CB8AE">
    <File Id="LVDMSCore10" Source="C:\Projects\LVDMS10\LVDMSServerConfig\LVDMSServerConfig\bin\Debug\LVDMSCore10.dll" KeyPath="yes" />
  </Component>
  <Component Id="LVDMSInstallationGuide" Guid="ECA2B30A-54CB-4DE4-A659-B429458BDF3A">
    <File Id="LVDMSInstallationGuide" Source="\\192.168.0.211\development\HelpFiles\LaserVault_DMS_10\LaserVault_DMS_Installation_Guide\LaserVault_DMS_Installation_Guide.pdf" KeyPath="yes" />
  </Component>
</ComponentGroup>

<ComponentGroup Id="Shortcuts" Directory="ProgramMenuDir">
  <Component Id="LVDMSServerConfigShortCut">
    <Shortcut Id="LVDMSServerConfigShortCut" Name="LVDMS Server Config" Description="LaserVault DMS Server Configuration" Target="[#LVDMSServerConfig]" WorkingDirectory="INSTALLFOLDER" />
    <RemoveFolder Id="ProgramMenuDir" On="uninstall"/>
    <RegistryValue Root="HKCU" Key="Software\LaserVault\LVDMS" Name="CurrentVersion" Type="string" Value="[ProductVersion]" KeyPath="yes" />
  </Component>
</ComponentGroup>

<ComponentGroup Id="RegistryEntries">
  <Component Id="RegistryLVDMSPath" Guid="9AE59D2B-EF16-4CAA-8A27-AA5BE00FAA07" Permanent="yes" Directory="TARGETDIR">
    <RegistryKey Root="HKLM" Key="Software\ESC">
      <RegistryValue Type="string" Name="LVDMSPath" Value="[INSTALLFOLDER]"/>
    </RegistryKey>
  </Component>
</ComponentGroup>

<Feature Id="Complete" Title="LaserVault DMS Server" Level="1">
        <ComponentGroupRef Id="ProductComponents" />
  <ComponentGroupRef Id="Shortcuts"/>
  <ComponentGroupRef Id="RegistryEntries"/>
    </Feature>
</Product>

2 个答案:

答案 0 :(得分:0)

我认为你走的是正确的道路。我通过以下方式解决了它(基本上与您尝试的完全相似,只是相反,即设置默认值并仅在注册表中找到值时覆盖它),使用以下步骤:

  • WIXUI_INSTALLDIR设置为目录结构定义的默认值:

    <Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />
    
  • 为以前的安装文件夹执行RegistrySearch

        <Property Id="PREVIOUSINSTALLFOLDER">
          <RegistrySearch Id="GetPreviousInstallFolder" Root="HKLM" Key="SOFTWARE\ESC" Name="LVDMSPath" Type="raw" />
        </Property>
    
  • 仅在找到值时设置INSTALLDIR

        <CustomAction Id="SetINSTALLDIR"  Property="INSTALLDIR" Value="[PREVIOUSINSTALLFOLDER]" Execute="firstSequence" />
        ...
        <InstallExecuteSequence>
                    <Custom Action="SetINSTALLDIR" After="AppSearch">PREVIOUSINSTALLFOLDER</Custom>
        </InstallExecuteSequence>
        <InstallUISequence>
                    <Custom Action="SetINSTALLDIR" After="AppSearch">PREVIOUSINSTALLFOLDER</Custom>
        </InstallUISequence>
    

答案 1 :(得分:0)

仅作以下准备,以供将来参考:

<!-- Determine the directory of a previous installation (if one exists) -->
<Property Id="INSTALLFOLDER">
    <RegistrySearch Id="GetInstallDir" Type="raw" Root="HKLM" Key="Software\ESC" Name="LVDMSPath" />
</Property>
...

<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />

这两个自定义操作都不是必需的。