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

*

* This example script searches a batch file and reports whether

* or not the file includes a command that references SHARE.EXE.

* It then finds and displays all PATH and SET PATH statements.

*

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

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

*       drive C. The batch file should include a command

*       to launch Share.exe, and it should contain at least

*       one PATH or SET PATH= statement.

*

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

 

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

 

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

#include "Ifx.h"

 

export prototype ExFn_BatchFind(HWND);

 

function ExFn_BatchFind(hMSI)

    STRING svResult;

    NUMBER nResult;

begin

 

    // Load the target batch file.

    if (BatchFileLoad (TARGET_BATCH ) < 0) then

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

        abort;

    endif;

 

    // Check for a SHARE.EXE command.

    nResult = BatchFind ("SHARE.EXE", svResult, COMMAND);

 

    if (nResult < 0) then

        MessageBox ("SHARE.EXE command not found.", WARNING);

    else

        MessageBox ("SHARE.EXE command found.", INFORMATION);

    endif;

 

    // Find the first PATH or SET PATH= statement.  Pass RESTART in

    // the third parameter to begin searching at the top of the file.

    nResult = BatchFind ("PATH", svResult, RESTART);

 

    if (nResult < 0) then

        MessageBox ("PATH command not found.", WARNING);

    else

 

        // Loop while PATH commands are found.

        while (nResult = 0)

            MessageBox (svResult, INFORMATION);

 

            // Find the next PATH command.  Pass CONTINUE in the

            // third parameter to continue the search with the

            // statement that follows the last match.

            nResult = BatchFind ("PATH", svResult, CONTINUE);

        endwhile;

 

        MessageBox ("No more PATH commands.", WARNING);

 

    endif;

 

end;