ListWriteToFile 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 ListReadFromFile and ListWriteToFile

* functions.

*

* ListReadFromFile is called to read and display the

* Autoexec.bat file. After the list has been displayed,

* a remark is appended to the end of the list and the list

* is written to a new file. The original file remains

* unchanged.

*

* Note: In order for this script to run correctly, there must

*       be a batch file named Autoexec.bat in the root

*       directory of drive C.

*

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

 

#define OLD_FILE "C:\\Autoexec.bat"

#define NEW_FILE "C:\\Autoexec.lst"

 

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

#include "Ifx.h"

 

export prototype ExFn_ListWriteToFile(HWND);

 

function ExFn_ListWriteToFile(hMSI)

    LIST listID;

begin

 

    // Create a string list.

    listID = ListCreate (STRINGLIST);

 

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

    if (listID = LIST_NULL) then

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

        abort;

    endif;

 

    // Read the file into a string list.

    if (ListReadFromFile (listID, OLD_FILE) < 0) then

        // Report ListReadFromFile failure.

        MessageBox ("Unable to read" + OLD_FILE + ".", SEVERE);

    else

        // Display the list.

        SdShowInfoList ("Demo", "The example list file:", listID);

 

        // Add a new string to the list.

        ListAddString (listID, "REM Added by IS setup.", AFTER);

 

        // Write the list to a file.

        if (ListWriteToFile (listID, NEW_FILE) < 0) then

            MessageBox ("Unable to write list to "+ NEW_FILE + ".", SEVERE);

        else

            MessageBox ("Successfully wrote list "+ NEW_FILE + ".", INFORMATION);

        endif;

    endif;

 

    // Remove the list from memory.

    ListDestroy (listID);

 

end;