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

*

* This example script moves lines within a batch file.  First,

* it calls BatchFileLoad to load the file.  Next, it moves

* the first PATH command to the end of the file.  Then it

* moves the first statement that references Share.exe ahead

* of the statement that launches Windows.

*

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

*       named ISExampl.bat in the root of drive C.  For

*       best effect, the first line in that file should

*       be a PATH command; the next statement should

*       launch Windows;  the last statement should execute

*       Share.exe.

*

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

 

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

#define BACKUP_BATCH "ISExampl.bak"

 

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

#include "Ifx.h"

 

export prototype ExFn_BatchMoveEx(HWND);

 

function ExFn_BatchMoveEx(hMSI)

begin

 

    // Load the batch file to be edited.

    if BatchFileLoad (TARGET_BATCH) < 0 then

        MessageBox ("Unable to load " + TARGET_BATCH+".", SEVERE);

        abort;

    endif;

 

    // Move the PATH statement to the end of the file.

    if (BatchMoveEx ("PATH", "", AFTER, 0) < 0) then

        MessageBox ("Unable to move PATH statement.", SEVERE);

    else

        MessageBox ("PATH statement moved to end of file.", INFORMATION);

    endif;

 

    // Move the SHARE.EXE command before the WIN statement.

    if (BatchMoveEx ("SHARE.EXE", "WIN", BEFORE|COMMAND, COMMAND) < 0) then

        MessageBox ("Unable to move SHARE.EXE statement.", SEVERE);

    else

        MessageBox ("SHARE.EXE statement moved before WIN statement.",

                   INFORMATION);

    endif;

 

    // Save the updated file; back up the original file.

    if BatchFileSave (BACKUP_BATCH) < 0 then

        MessageBox ("Unable to save " + BACKUP_BATCH+".", SEVERE);

    else

        MessageBox ("Batch file saved. Backup created.", INFORMATION);

    endif;

 

end;