1

I am making installer for a utility that can be installed as part of a main program or independently. The location of the main program in present in a registry key. If the main program is installed, the utility should be installed in a "Utilities" sub-directory. e.g. D:\Program Files(x86)\MainProgram\Utilities. If the main program is not installed, then it should default to root drive folder e.g. C:\Program Files(x86)\MainProgram\Utilities.

Installation should get the registry key (e.g. HKLM\Software\MainProgram\ Key:"Install_location"). This will give a path till d:\Program File(x86)\MainProgram. The utility should be installed in its sub-directly. If the key is not present, it should default to the standard location.

goto
  • 433
  • 3
  • 13

2 Answers2

1

Read the registry value from custom action using C# or some other language and check if key exists or else you can use WIX to find if registry key exists.

RegistryKey regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\MainProgram\Key");

if ((string)Registry.GetValue(regKey, "Install_location", "0") != "0")
{
    session["Somevariable"] = (string)Registry.GetValue(regKey, "Install_location")
}

using WIX

<Property Id="INSTALLLOCATION">
      <RegistrySearch Id="INSTALLLOCATION"
              Name="Install_location"
              Root="HKLM"
              Key="Software\MainProgram\Key"
              Type="raw" />
</Property>

On the basis of the value of WIX session variable you can decide the install location and install the utility at the desired path.

Sunil Agarwal
  • 4,097
  • 5
  • 44
  • 80
1

Read the MainProgram location into a property:

<Property Id="MainProgramDir">
    <RegistrySearch Id="FindMainProgramDir"
                Root="HKLM"
                Key="Software\MainProgram"
                Name="Install_location"
                Type="directory" />
</Property>

And set up your directory structure for the default behavior:

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="ProgramFilesFolder">
    <Directory Id="MainProgramDir" Name="MainProgram">
      <Directory Id="INSTALLDIR" Name="Utilities"/>
    </Directory>
  </Directory>
</Directory>

Directory elements are like properties, and will be overridden if there is a property with the same Id. If the property is not set (because the RegistrySearch fails) then it will be as it was defined in the directory structure you set up.

Dave Andersen
  • 5,337
  • 3
  • 30
  • 29
  • Wanna try answering this as well? http://stackoverflow.com/questions/19355537/wix-setting-install-folder-correctly – CodeMonkey Oct 15 '13 at 08:13