ConfigSetInt Example

InstallShield 2020 ยป 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.

/*-----------------------------------------------------------*\

*

* InstallShield Example Script

*

* Demonstrates the ConfigGetInt and ConfigSetInt functions.

*

* This example script gets the current value of the FILES

* command from a configuration file.  If a FILES command is not

* found, the command FILES=40 is added to the file.  If a FILES

* command is found, its value is tested. If the value is less

* than 40, the command is replaced with the command FILES=40.

*

* Note: Before running this script, create a configuration file

*       called ISExampl.sys in the root directory of drive C.

*       That file should include the following line:

*

*       FILES=20;

*

\*-----------------------------------------------------------*/

 

 

#define EXAMPLE_SYS "C:\\ISExampl.sys"

#define EXAMPLE_BAK "ISExampl.bak"

 

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

#include "Ifx.h"

 

export prototype ExFn_ConfigSetInt(HWND);

 

function ExFn_ConfigSetInt(hMSI)

    NUMBER nvValue;

    BOOL   bFileChanged;

begin

 

    // Load the configuration file.

    if (ConfigFileLoad (EXAMPLE_SYS) < 0) then

        MessageBox ("Unable to load " + EXAMPLE_SYS + ".", SEVERE);

        abort;

    endif;

    

    // Initialize indicator to show if file was updated.

    bFileChanged = FALSE;

    

    // Find the command "FILES" in the configuration file.

    if (ConfigGetInt ("FILES", nvValue) < 0) then

    

        // No FILES command found. Add FILES command.

        if ConfigAdd ("FILES", "40", "", AFTER) = 0 then

            MessageBox ("FILES=40 added to " + EXAMPLE_SYS + ".", INFORMATION);

            bFileChanged = TRUE;

        else

            MessageBox ("FILES command not found. Unable to update " +

                        EXAMPLE_SYS + ".", SEVERE);

        endif;

    

    else

    

        // FILES command found.

        if (nvValue >= 40) then

            // FILES command setting is ok.

            SprintfBox (INFORMATION, "ConfigGetInt Example",

                       "FILES=%d; no change required.", nvValue);

        else

 

            // FILES command needs to be changed.

            if (ConfigSetInt ("FILES", 40) < 0) then

                MessageBox ("Unable to update "+EXAMPLE_SYS + ".", SEVERE);

            else

                MessageBox ("The FILES setting was changed to 40.", INFORMATION);

                bFileChanged = TRUE;

            endif;

    

        endif;

    

    endif;

    

    // If the file was edited, save it.

    if bFileChanged then

    

        // Back up the original file with the extension 'bak'; save the

        // edited file under its original name.  If ISExamp1.bak already

        // exists, ConfigFileSave will generate a numbered extension.

        if (ConfigFileSave (EXAMPLE_BAK) < 0) then

            MessageBox ("Unable to save " + EXAMPLE_SYS + ".", SEVERE);

        else

            MessageBox (EXAMPLE_SYS + " saved.",INFORMATION);

        endif;

 

    endif;

 

end;