VarSave Stack Example

InstallShield 2016 » InstallScript Language Reference

Note • To call this function in a Basic MSI setup, you must first create a custom action for the entry-point function, execute the custom action in a sequence or as the result of a dialog's control event, and then build the release.

// This script fragment illustrates how VarSave

// and VarRestore work with an internal stack

// to save and retrieve the values assigned to

// SRCDIR and INSTALLDIR

 

// Include Ifx.h for built-in InstallScript function prototypes.

#include "Ifx.h"

 

export prototype ExFn_VarSave Stack(HWND);

 

function ExFn_VarSave Stack(hMSI)

begin

 

    // Store the starting values of SRCDIR and INSTALLDIR

    VarSave(SRCTARGETDIR);

 

    // Assign new values to SRCDIR and INSTALLDIR

    SRCDIR    = "E:\\";

    INSTALLDIR = "C:\\Program Files";

 

    // . . .

 

    // Store those values ("E:\\" and "C:\\Program Files")

    VarSave(SRCTARGETDIR);

 

    // Assign new values to SRCDIR and INSTALLDIR

    SRCDIR    = "A:\\";

    INSTALLDIR = "C:\\Windows";

 

    // . . .

 

    // Store those new values ("A:\\" and "C:\\Windows")

    VarSave(SRCTARGETDIR);

 

    // . . .

 

    // Restore the values from the third call to VarSave

    VarRestore(SRCTARGETDIR);

 

    // SRCDIR is now "A:\\

    // INSTALLDIR is now "C:\\Windows"

 

    // . . .

 

    // Restore the values from the second call to VarSave

    VarRestore(SRCTARGETDIR);

 

    // SRCDIR is now "E:\\"

    // INSTALLDIR is now "C:\\Program Files"

 

    // . . .

 

    // Restore the values from the first call to VarSave

    VarRestore(SRCTARGETDIR);

 

    // SRCDIR and INSTALLDIR now have their starting values.

 

end;