EzBatchAddString Example

InstallShield 2015 ยป 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 EzBatchAddString function.

*

* This script performs four operations on a batch file:

*

* -- First, it adds a comment line at the top of the file.

*

* -- Next, it adds the line "SET TEMP=C:\EXAPP3", placing it

*    it after the PATH statement.

*

* -- Then, it adds the command "C:\EXAPP3\EXAPP.EXE", placing

*    it after the "SET TEMP=C:\EXAPP3" statement.

*

* -- Finally, it replaces the existing PATH statement with a

*    new PATH statement.

*

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

*       named ISExampl.bat and store it in the root of

*       drive C.  For best effect, include a PATH statement

*       in that file.

*

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

 

#define BATCH_FILE "C:\\ISExampl.bat"

 

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

#include "Ifx.h"

 

export prototype ExFn_EzBatchAddString(HWND);

 

function ExFn_EzBatchAddString(hMSI)

    STRING szLine, szRefKey;

    NUMBER nOptions;

begin

 

    // Set the default batch file.

    BatchSetFileName (BATCH_FILE);

 

    // Set up parameters for next call to EzBatchAddString.

    szLine    = "rem This is the first line of the file.";

    szRefKey  = "";

    nOptions  = BEFORE|NOSET;

 

    // Add a comment line to the top of the batch file.

    if (EzBatchAddString (szLine, szRefKey, nOptions) < 0) then

        MessageBox ("First call to EzBatchAddString failed.", SEVERE);

    else

        MessageBox ("First call to EzBatchAddString successful.", INFORMATION);

    endif;

 

    // Set up parameters for next call to EzBatchAddString.

    szLine    = "TEMP=C:\\EXAPP3";

    szRefKey  = "PATH";

    nOptions  = AFTER;

 

    // Add a line after the PATH statement.

    if (EzBatchAddString (szLine, szRefKey, nOptions) < 0) then

        MessageBox ("Second call to EzBatchAddString failed.", SEVERE);

    else

        MessageBox ("Second call to EzBatchAddString successful.", INFORMATION);

    endif;

 

    // Set up parameters for next call to EzBatchAddString.

    szLine    = "C:\\EXAPP3\\EXAPP.EXE";

    szRefKey  = "TEMP";

    nOptions  = AFTER|NOSET;

 

    // Add a command line after the SET TEMP statement.

    if (EzBatchAddString (szLine, szRefKey, nOptions) < 0) then

        MessageBox ("Third call to EzBatchAddString failed.", SEVERE);

    else

        MessageBox ("Third call to EzBatchAddString successful.", INFORMATION);

    endif;

 

    // Set up parameters for next call to EzBatchAddString.

    szLine    = "PATH=C:\\;C:\\Windows";

    szRefKey  = "PATH";

    nOptions  = AFTER|NOSET|REPLACE|COMMAND;

 

     // Replace the PATH statement.

    if (EzBatchAddString (szLine, szRefKey, nOptions) < 0) then

        MessageBox ("Fourth call to EzBatchAddString failed.", SEVERE);

    else

        MessageBox ("Fourth call to EzBatchAddString successful.", INFORMATION);

    endif;

 

endprogram