Jalmar Tõnsau
Jalmar Tõnsau

Reputation: 126

Wix installer creating registry entry based on user input

So, basically what I have is Wix installer, which is modified and I am currently stuck at a problem with registry entry. During install the Installer has a custom dialogue, where user has to choose/insert second path. Which will be stored in the Registry. But instead of inserting what user entered, it inserts "[INSTALLFOLDER]", although it should look something like "C:\Program Files...". I did some research but, didn't find anything that could help me. All of the code are in the same file.

Main parts of the code are here, first there's this property. Which later should be written into registry.

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

Later on there's the custom window.

<!-- 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 -->

Little bit below that is this publish part...

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

And this works for me. I replaced guid for "reasons". Registry path and everything else seems to be fine, just one thing which is not working,adding [CUSTOMPATH] property as registry value.I also tried without [] brackets, and so on... Even tried it with [Manufacturer], worked perfectly fine, inserted Manufacturer into registry. But this here is not working.

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

Upvotes: 1

Views: 918

Answers (2)

Jalmar T&#245;nsau
Jalmar T&#245;nsau

Reputation: 126

So basically what I did to fix this issue was that I created right beside INSTALLFOLDER another directory. Since I didn't add any files into it, that folder will not be created, but value as such remains.

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

Registry entry now looks like this:

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

And Property like this:

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

Folder selector controls look like this, so both typing and button (folder selector) work. Dialog that uses them is exactly like InstallDirDlg, but with a different name.

<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)" />

Upvotes: 1

Starceaker
Starceaker

Reputation: 631

Correct

This is correct because you specify that the content of CUSTOMPATH is actually a reference a different Property (or Directory because a certain point Directory elements become available to be used like Property elements):

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

The above will visualize the content of INSTALLFOLDER so that's ok. However, the actual value of CUSTOMPATH will never change. It should always remain a reference to another property because you use it with Indirect=Yes.

Possible root cause of your problem

In the next part you assign a value to CUSTOMPATH and that's where I think something goes wrong. I tried the following and it gave me the requested result ("C:\Program Files..." in the registry value).

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

If this doesn't work, could you provide me with the logfile?

zzz.msi /lvoicewarmupx debug.log

Upvotes: 2

Related Questions