installshield

InstallShield 2023 Basic MSI: How to change the value of INSTALLDIR at runtime?


I am creating a Basic MSI project, which needs to copy its files to a location which differs at runtime.

I have tried setting INSTALLDIR's value at runtime with a Custom Action. This works in the debugger (in the After Install Initialize exec sequence), but not if the MSI file is moved to another folder and run directly from there (outside of the debugger).

I have also tried setting INSTALLDIR in other exec sequence Custom Actions, to no avail.

Code is as follows:

 // Called at various exec sequences, including After Cost Finalize
function AfterXXX(hMSI)
    // To Do: Declare local variables.
    STRING szMsg;
    NUMBER nResult;
begin
    if (!SetXXXFolders()) then
        szMsg = "Unable to retrieve XXX install path. The installation will not continue.";
       MessageBox(szMsg, SEVERE);
       return ERROR_INSTALL_FAILURE;
    endif;

    // Set INSTALLDIR to szPrograms (confirmed properly populated)
    INSTALLDIR = szPrograms;

    return ERROR_SUCCESS;
end;

InstallShield version is InstallShield 2023 Premiere.

Any thoughts on what might be amiss?


Solution

  • The solution was to set both the INSTALLDIR property and the INSTALLDIR target path in an After Cost Finalize handler.

    // INSTALLDIR is updated with a string variable.
    MsiSetProperty(hMSI, "INSTALLDIR", svPrograms); 
    MsiSetTargetPath(hMSI, "INSTALLDIR", svPrograms);
    

    With this done, INSTALLDIR had the correct path, and the installation copied the files to the correct location.