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

*

* The AskText dialog is displayed to obtain a line of text

* from the user.  This text is then inserted as the first line

* in the text file specified by TARGET_FILE.

*

* FileInsertLine is then called again to append the same text

* to the first line, leaving two copies of the same text in

* the first line of the file.

*

* Note: Before running this script, create a batch file named

*       ISExampl.bat in the root of drive SRCDIR.

*

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

 

#define TARGET_FILE  "ISExampl.bat"

#define TITLE        "FileInsertLine Example"

 

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

#include "Ifx.h"

 

export prototype ExFn_FileInsertLine(HWND);

 

function ExFn_FileInsertLine(hMSI)

    STRING szMsg, svText;

begin

 

    // Set up message parameter for call to AskText.

    szMsg = "Please enter a line to insert into EXAMPLE.BAT.";

 

    // Get line to add to file.

    AskText (szMsg, "", svText);

 

    // Insert the text as the first line of the specified file.

    if (FileInsertLine (TARGET_FILE, svText, 0, BEFORE) < 0) then

        MessageBox ("FileInsertLine failed.", SEVERE);

    else

        // Set up message parameter for call to SprintfBox.

        szMsg    = "'%s' successfully inserted as first line of %s.";

 

        // Display message.

        SprintfBox (INFORMATION, TITLE, szMsg, svText, TARGET_FILE);

    endif;

 

    // Append the same string to the same line.

    if (FileInsertLine(TARGET_FILE, svText, 0, APPEND) < 0) then

        MessageBox("FileInsertLine failed.", SEVERE);

    else

        // Set up message parameter for call to SprintfBox.

        szMsg    = "'%s' successfully appended to first line of %s.";

 

        // Display message.

        SprintfBox(INFORMATION, TITLE, szMsg, svText, TARGET_FILE);

    endif;

 

end;