Wix安装程序根据用户输入创建注册表项

时间:2015-12-15 14:36:24

标签: windows wix registry

所以,基本上我所拥有的是Wix安装程序,它已被修改,我目前陷入了注册表项的问题。在安装过程中,安装程序有一个自定义对话框,用户必须选择/插入第二个路径。哪个将存储在注册表中。但是它不是插入用户输入的内容,而是插入“[INSTALLFOLDER]”,尽管它应该看起来像“C:\ Program Files ...”。我做了一些研究,但没有找到任何可以帮助我的东西。 所有代码都在同一个文件中。

代码的主要部分在这里,首先是这个属性。以后应该写入注册表。

<Property Id="CUSTOMPATH" Value="INSTALLFOLDER" Secure="yes" />

稍后会有自定义窗口。

<!-- NetWork path -->
  <Dialog Id="CustomNETDirDlg" Width="370" Height="270" Title="Custom Folder">
    <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="!(loc.WixUINext)" />
    <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="!(loc.WixUIBack)" />
    <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="!(loc.WixUICancel)">
      <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
    </Control>
    <Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes" Text="Choose Network Path" />
    <Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes" Text="NetWork Path" />
    <Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="!(loc.InstallDirDlgBannerBitmap)" />
    <Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" />
    <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />
    <Control Id="FolderLabel" Type="Text" X="20" Y="60" Width="290" Height="30" NoPrefix="yes" Text="Choose / Enter Path" />
    <Control Id="NETFOLDER" Type="Edit" X="20" Y="100" Width="320" Height="18" Text="{200}" Property="CUSTOMPATH" Indirect="yes"/>
    <Control Id="CustomChangeFolder" Type="PushButton" X="20" Y="120" Width="56" Height="17" Text="!(loc.InstallDirDlgChange)" />
  </Dialog>
  <!-- / NetWork path -->

下面就是这个发布部分......

  <Publish Dialog="CustomNETDirDlg" Control="Back" Event="NewDialog" Value="InstallDirDlg">1</Publish>
  <Publish Dialog="CustomNETDirDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="4">1</Publish>
  <Publish Dialog="CustomNETDirDlg" Control="CustomChangeFolder" Property="_BrowseProperty" Value="[CUSTOMPATH]" Order="1">1</Publish>
  <Publish Dialog="CustomNETDirDlg" Control="CustomChangeFolder" Event="SpawnDialog" Value="BrowseDlg" Order="2">1</Publish>

这对我有用。 我为“原因”取代了guid。注册表路径和其他一切似乎都很好,只有一件事不起作用,添加[CUSTOMPATH]属性作为注册表值。我也试过没有[]括号,依此类推......甚至试过[制造商],工作完全没问题,将制造商插入注册表。但这里没有用。

<DirectoryRef Id="TARGETDIR">
    <Component Id="RegistryEntries" Guid="{my guid}">
      <RegistryValue Root='HKMU' Key='Software\[Manufacturer]\[ProductName]' Type='string' Value='[CUSTOMPATH]' KeyPath='yes' />
    </Component>
</DirectoryRef>

2 个答案:

答案 0 :(得分:1)

<强>正确

这是正确的,因为你指定CUSTOMPATH的内容实际上是一个不同的属性(或目录,因为某个点的目录元素可以像Property元素一样使用):

<Property Id="CUSTOMPATH" Value="INSTALLFOLDER" Secure="yes" />
<Control Id="NETFOLDER" Type="Edit" X="20" Y="100" Width="320" Height="18" Text="{200}" Property="CUSTOMPATH" Indirect="yes"/>

以上内容将显示INSTALLFOLDER的内容,这样就可以了。 但是,CUSTOMPATH的实际值永远不会改变。它应始终保持对另一个属性的引用,因为您将其与Indirect = Yes一起使用。

问题的可能根本原因

在下一部分中,您将为CUSTOMPATH分配一个值,以及我认为出现问题的地方。我尝试了以下内容,它给了我所请求的结果(&#34; C:\ Program Files ...&#34;在注册表值中)。

<Publish Dialog="CustomNETDirDlg" Control="CustomChangeFolder" Property="_BrowseProperty" Value="[INSTALLFOLDER]" Order="1">1</Publish>
<RegistryValue Root='HKLM' Key='Software\Test\TestRegEntry1' Type='string' Value='[INSTALLFOLDER]' KeyPath='yes'/>

如果这不起作用,您可以向我提供日志文件吗?

zzz.msi /lvoicewarmupx debug.log

答案 1 :(得分:1)

所以基本上我解决这个问题的方法是我在INSTALLFOLDER另一个目录旁边创建的。由于我没有添加任何文件,因此不会创建该文件夹,但仍然会保留这些文件。

<Directory Id="INSTALLFOLDER2" Name="!(bind.property.ProductName)"></Directory>                   
<Directory Id="INSTALLFOLDER" Name="!(bind.property.ProductName)">
    <!-- Here are files I wanted to include -->
</Directory>

注册表项现在看起来像这样:

<DirectoryRef Id="TARGETDIR">
    <Component Id="RegistryEntries" Guid="here comes your guid">
        <RegistryValue Root='HKMU' Key='Software\[Manufacturer]\[ProductName]' Type='string' Value="[INSTALLFOLDER2]" KeyPath='yes' />
    </Component>
</DirectoryRef>

和这样的财产:

<Property Id="CUSTOMPATH" Value="INSTALLFOLDER2" Secure="yes" />

文件夹选择器控件如下所示,因此键入和按钮(文件夹选择器)都有效。使用它们的对话框与InstallDirDlg完全相同,但名称不同。

<Control Id="NETFOLDER" Type="Edit" X="20" Y="100" Width="320" Height="18" Text="{200}" Property="CUSTOMPATH" Indirect="yes" />
<Control Id="CustomChangeFolder" Type="PushButton" X="20" Y="120" Width="56" Height="17" Text="!(loc.InstallDirDlgChange)" />