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

*

* This script prompts the user to input the name of a program

* folder on the target system.  ListFindString is then called

* to search for this folder name in a list that contains all

* folder names on the target system.  A message is displayed

* to report the results of the search.

*

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

 

#define TITLE_TEXT "ListFindString Example"

 

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

#include "Ifx.h"

 

export prototype ExFn_ListFindString(HWND);

 

function ExFn_ListFindString(hMSI)

    STRING szString;

    LIST   listID, listSubfoldersID;

    NUMBER nResult;

begin

 

    // Create string lists

    listID = ListCreate (STRINGLIST);  

    listSubfoldersID = ListCreate (STRINGLIST);  

 

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

    if (listID = LIST_NULL) || (listSubfoldersID = LIST_NULL) then

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

        abort;

    endif;

 

    // Fill the list with the names of program folders.

    GetFolderNameList (FOLDER_PROGRAMS, listID, listSubfoldersID);

 

    // Prompt user to enter a folder name.

    AskText ("Please enter the name of an existing program folder:",

            "", szString);

 

    // Make the first list element the current element

    // so ListFindItem will search from the top of the list.

    ListSetIndex (listSubfoldersID, 0);

 

    // Search the list for the folder name entered by the user.

    // Reminder: The string comparison is case sensitive.

    nResult = ListFindString (listSubfoldersID, szString);

 

    // Report the search result.

    if (nResult < 0) then

        MessageBox ("ListFindString failed.", SEVERE);

    elseif (nResult = END_OF_LIST) then

        SprintfBox (WARNING, TITLE_TEXT, "%s could not be found.", szString);

    elseif (nResult = 0) then

        SprintfBox (INFORMATION, TITLE_TEXT, "ListFindString found: %s.",

                   szString);

    endif;

 

    // Remove list from memory.

    ListDestroy (listID);  

    ListDestroy (listSubfoldersID);

 

end;