GetProfString 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.

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

*

* InstallShield Example Script

*

* Demonstrates the functions AddProfString and GetProfString.

*

* This script adds a profile string to a file; then it

* retrieves and displays the string that was added.

*

* Note: The first time you run this script, it will create a

*       file named ISExampl.ini in the root of drive C. You

*       may delete that file when you have finished analyzing

*       this script.

*

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

 

#define EXAMPLE_INI "C:\\ISExampl.ini"

 

// The new section, key, and value to add to the file.

#define NEW_SECTION "New Section"

#define NEW_KEY     "New Key"

#define NEW_VALUE   "Test"

 

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

#include "Ifx.h"

 

export prototype ExFn_GetProfString(HWND);

 

function ExFn_GetProfString(hMSI)

    STRING svResult;

begin

 

    // Add the profile string to the file.

    if (AddProfString (EXAMPLE_INI, NEW_SECTION, NEW_KEY, NEW_VALUE) != 0) then

        // Display an error message if the string could not be added.

        MessageBox ("AddProfString failed.", SEVERE);

    else

        // Retrieve the value of a key from the file.

        if (GetProfString (EXAMPLE_INI, NEW_SECTION, NEW_KEY, svResult) != 0) then

            // Display an error message if the string could not be retrieved.

            MessageBox ("GetProfString failed.", SEVERE);

        else

            // Display the key and its current value.

            MessageBox (NEW_KEY + "=" + svResult, INFORMATION);

        endif;

    endif;

 

end;