StrGetTokens 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 StrGetTokens function.

*

* First, the value of a key is retrieved from an initialization

* file.  The value returned is a search path.  Then

* StrGetTokens is called to build a list of the paths found in

* the search path.  Finally, the paths are displayed.

*

* In order for this script to run correctly, you must create

* an initialization (text) file and add the following lines to

* it:

*

*    [Test Section]

*    searchpath=C:\Windows;C:\Windows\System;C:\Windows\Command

*

* Then set the constant EXAMPLE_INI to the fully qualified name

* of that file.

*

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

 

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

#define SECTION_NAME "Test Section"

#define KEY_NAME     "searchpath"

 

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

#include "Ifx.h"

 

export prototype ExFn_StrGetTokens(HWND);

 

function ExFn_StrGetTokens(hMSI)

    LIST   listID;

    STRING svSearchPath;

    STRING szTitle, szMsg;

begin

 

    // Get the value of the specified key from the specified section

    // of the initialization file.

    if GetProfString (FILE_NAME, SECTION_NAME, KEY_NAME, svSearchPath) < 0 then

      // Report the error.

      MessageBox ("Unable to retrieve key value from "+ FILE_NAME + ".", INFORMATION);

    else

        // Create a list to hold the paths that make up the search path

        // that was returned by GetProfString.

        listID = ListCreate (STRINGLIST);

 

        // Get each path from the search path into the list.

        if (StrGetTokens (listID, svSearchPath, ";") < 0) then

            // Report the error.

            MessageBox ("StrGetTokens failed.", SEVERE);

        else

            // Display the individual paths from the list.

            Sprintf (szMsg, "Paths found in %s %s", SECTION_NAME,KEY_NAME);

            SdShowInfoList ("Search Path", szMsg, listID);

        endif;

    endif;

 

    // Remove the list from memory.

    ListDestroy (listID);

 

end;