VarSave

InstallShield 2015 » InstallScript Language Reference

The VarSave function saves the current values of the system variables TARGETDIR (in InstallScript installations), INSTALLDIR ( in Basic MSI and InstallScript MSI installations), SRCDIR, or HKEYCURRENTROOTKEY, which are used by many other InstallScript functions. Call VarSave whenever you need to change the value of these system variables temporarily, for example, to set source and target directories before a call to XCopyFile. Afterwards, set those variables back to their previous values by calling VarRestore.

Syntax

VarSave (nType);

Parameters

VarSave Parameters

Parameter

Description

nType

Specifies which system variables to save. Pass one or more of the following predefined constants in this parameter. Note that you can pass multiple constants separated by the OR operator (||).

Project: This information applies to InstallScript projects:

VAR_LOGGING—Resets any stored uninstallation logging entries.
VAR_CURRENTDIR—Resets any stored current directory entries.
VAR_ALLSUPPORTED—Resets all stored entries.
VAR_HKEYCURRENTROOTKEY—Resets any stored current root key entries.
VAR_REGOPTIONS—Resets any stored current registry options.
CURRENTROOTKEY—This constant is obsolete. Use VAR_HKEYCURRENTROOTKEY instead.

Project: This constant applies to Basic MSI, InstallScript, and InstallScript MSI projects:

VAR_SRCTARGETDIR or SRCTARGETDIR—Resets any stored current TARGETDIR (in InstallScript installations), INSTALLDIR (in Basic MSI and InstallScript MSI installations), and SRCDIR entries.

Project: This constant applies to Basic MSI and InstallScript MSI projects:

SRCINSTALLDIR—This constant is obsolete. Use VAR_SRCTARGETDIR instead.

Return Values

VarSave Return Values

Return Value

Description

0

Indicates that the current values of the system variables were saved.

< 0

Indicates that the values were not saved due to an internal error. This error should occur only if the system is low on available memory.

Additional Information

Each time you call VarSave, the InstallScript engine pushes the current values of the system variables onto an internal stack, which operates as a last in, first out storage area. This method allows you to stack a series of values in memory. You can then make calls to VarRestore to retrieve those values from the stack in the opposite order that you stored them.

For example, if you call VarSave three times with SRCTARGETDIR as its argument (without calling VarRestore in between those calls), there will be three sets of SRCDIR and TARGETDIR values on the stack. The first call to VarRestore with SRCTARGETDIR as its argument restores the values from the third call to VarSave. The next call to VarRestore restores the values from the second call to VarSave. The third call to VarRestore restores the values from the first call to VarSave. At that point, the stack is empty. To see a script fragment that illustrates this process, refer to VarSave Stack Example.

See Also