GetProfStringList Example

InstallShield 2024 » InstallScript Language Reference

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

*

* InstallShield Example Script

*

* Demonstrates the function GetProfStringList.

*

* This script retrieves keys and their values from an

* initialization file.

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

 

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

 

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

#define SECTION "InstallShield"

#define KEY1     "Key1"

#define KEY2     "Key2"

#define KEY3     "Key3"

#define KEY4     "Key4"

#define KEY5     "Key5"

#define VALUE1   1

#define VALUE2   2

#define VALUE3   3

#define VALUE4   4

#define VALUE5   5

 

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

#include "Ifx.h"

 

  export prototype ExFn_GetProfString(HWND);

 

function ExFn_GetProfString(hMSI)

    STRING svResult, svKeyName, svKeyVal;

    LIST listKeyNames, listKeyValues;

    NUMBER nVal;

begin

 

    // Add the profile strings to the file.

    WriteProfInt (EXAMPLE_INI, SECTION, KEY1, VALUE1);

    WriteProfInt (EXAMPLE_INI, SECTION, KEY2, VALUE2);

    WriteProfInt (EXAMPLE_INI, SECTION, KEY3, VALUE3);

    WriteProfInt (EXAMPLE_INI, SECTION, KEY4, VALUE4);

    WriteProfInt (EXAMPLE_INI, SECTION, KEY5, VALUE5);

 

    // Create a list to hold the key names;

    listKeyNames = ListCreate(STRINGLIST);

 

    // If an error occurred, report it; then terminate.

    if (listKeyNames = LIST_NULL) then

        MessageBox ("Unable to create list.", SEVERE);

        //Add your custom error handling code here.

        abort;

    endif;

 

    // Create a list to hold the key values;

    listKeyValues = ListCreate(STRINGLIST);

 

    // If an error occurred, report it; then terminate.

    if (listKeyValues = LIST_NULL) then

        MessageBox ("Unable to create list.", SEVERE);

        //Add your custom error handling code here.

        abort;

    endif;

 

    // Retrieve the keys from the specified section of the file.

    nVal = GetProfStringList (EXAMPLE_INI, SECTION,

                             listKeyNames, listKeyValues);

 

    if (nVal = 0) then

        nVal = ListGetFirstString (listKeyNames, svKeyName);

 

        if (nVal = END_OF_LIST) then

            MessageBox("No keys found in [" + SECTION + "]", WARNING);

        else

            ListGetFirstString (listKeyValues, svKeyVal);

 

            repeat

                // Display the keys and their values.

                MessageBox(svKeyName + "=" + svKeyVal, INFORMATION);

 

                nVal = ListGetNextString (listKeyNames, svKeyName);

                if !(nVal = END_OF_LIST) then

                    ListGetNextString (listKeyValues, svKeyVal);

                endif;

 

            until nVal = END_OF_LIST;

 

        endif;

    endif;

 

end;