Overriding the Installation Directory |
The following is an example where the installation directory is specified by an environment variable but it could just as easily have been created via an immediate "VbsCa" custom action.
Note that Windows Installer remembers the location for repair and uninstall (at least where at least one file is installed there).
#define ENVVAR_INSTALLDIR SOME_ENV_VAR ;;Name of environment variable containing a path... <$DirectoryTree Key="INSTALLDIR" Dir="C:\DummyLocation" CHANGE="\" PrimaryFolder="Y"> #( ;--- Check that the environment variable holding the install dir exists! --- <$AbortIf Condition=^%<$ENVVAR_INSTALLDIR> = "" and <$CONDITION_INSTALL_ONLY>^ Seq=^CostFinalize-^ SeqTable="InstallUISequence InstallExecuteSequence" Message=^The "<$ENVVAR_INSTALLDIR>" environment variable doesn't exist. We can't determine the installation directory.^ > ;--- Set the installation directory to the value of the environment variable --- <$PropertyCa "INSTALLDIR" Value="[%<$ENVVAR_INSTALLDIR>]" DIR="Y" Condition=^<$CONDITION_INSTALL_ONLY>^ Seq=^CostFinalize-^ SeqTable="InstallUISequence InstallExecuteSequence" > #) ;--- Install files ---------------------------------------------------------- <$Files "TryMe.*" DestDir="INSTALLDIR">
Remember the Install location |
This shows one way you can insure that the install location (in this case "INSTALLDIR") is remembered but defaults to a good value the first time:
;--- Create INSTALLDIR (remember where user wishes it installed) ------------ <$Property "INSTALLDIR" Persist="Y" PersistHow="PRODUCT FOREVER"> <$DirectoryTree Key="INSTALLDIR" Dir="[ProgramFilesFolder]\SomeProduct" CHANGE="\" PrimaryFolder="Y"> ...
Note that the "PropertyCa" was not needed in the above, if you need to "work out" the correct install location then it would probably be used to set the "INSTALLDIR" property's value (with or without the "DIR" parameter specified as "Y").