InstallShield 2016 » InstallScript Language Reference
The following example applies to:
InstallScript/InstallScript MSI Installations
/*-----------------------------------------------------------*\
*
* InstallShield Example Script
*
* Demonstrates the BatchAdd function.
*
* This example script adds three statements to a batch file.
* First, it adds a PATH statement. Next, it adds a command to
* set the environment variable EXENV. Then it adds a command
* to launch SHARE.EXE, placing it before the existing command
* to start Windows. Finally, it backs up the original file
* and saves the edited file under its original name.
*
* If any of the calls to BatchAdd fails, the setup exits
* without saving changes to the batch file.
*
* Note: Before running this script, create a batch file
* named ISExampl.bat in the root of drive C. For
* best effect, that file should include the following
* lines:
*
* PATH=C:\Windows
* Win
*
\*-----------------------------------------------------------*/
#define EXAMPLE_BAT "C:\\ISEXAMPL.BAT"
#define EXAMPLE_BAK "ISEXAMPL.BAK"
STRING szPath;
// Include Ifx.h for built-in InstallScript function prototypes.
#include "Ifx.h"
function OnBegin()
begin
// Load the batch file to be edited.
if (BatchFileLoad (EXAMPLE_BAT) < 0) then
MessageBox ("Unable to load " + EXAMPLE_BAT+".", SEVERE);
abort;
endif;
// Add a SET PATH command that appends the value of an existing
// search path to C:\EXAPP\BIN.
szPath = "C:\\EXAPP\\BIN;%PATH%";
if (BatchAdd ("PATH", szPath, "PATH", AFTER) < 0) then
MessageBox ("First call to BatchAdd failed", WARNING);
abort;
endif;
// Add the line SET EXENV = C:\OTHERAPP\BIN. If the
// environment variable EXENV already exists in the batch
// file, the last SET EXENV statement is replaced.
szPath = "C:\\OTHERAPP\\BIN";
if (BatchAdd ("EXENV", szPath, "EXENV", REPLACE) < 0) then
MessageBox ("Second call to BatchAdd failed", WARNING);
abort;
endif;
// Add the command SHARE.EXE before the command WIN.
if (BatchAdd ("", "SHARE.EXE", "WIN", BEFORE | COMMAND) < 0) then
MessageBox ("Third call to BatchAdd failed", WARNING);
abort;
endif;
// Save the updated file; back up the original file.
if (BatchFileSave(EXAMPLE_BAK) < 0) then
MessageBox ("Unable to save " + EXAMPLE_BAK + ".", SEVERE);
else
MessageBox ("Batch file saved. Backup created.",INFORMATION);
endif;
end;
The following example applies to:
Basic MSI Installations
Tip • 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 BatchAdd function.
*
* This example script adds three statements to a batch file.
* First, it adds a PATH statement. Next, it adds a command to
* set the environment variable EXENV. Then it adds a command
* to launch SHARE.EXE, placing it before the existing command
* to start Windows. Finally, it backs up the original file
* and saves the edited file under its original name.
*
* If any of the calls to BatchAdd fails, the setup exits
* without saving changes to the batch file.
*
* Note: Before running this script, create a batch file
* named ISExampl.bat in the root of drive C. For
* best effect, that file should include the following
* lines:
*
* PATH=C:\Windows
* Win
*
\*-----------------------------------------------------------*/
#define EXAMPLE_BAT "C:\\ISEXAMPL.BAT"
#define EXAMPLE_BAK "ISEXAMPL.BAK"
// Include Ifx.h for built-in InstallScript function prototypes.
#include "Ifx.h"
export prototype ExFn_BatchAdd(HWND);
function ExFn_BatchAdd(hMSI)
STRING szPath;
begin
// Load the batch file to be edited.
if (BatchFileLoad (EXAMPLE_BAT) < 0) then
MessageBox ("Unable to load " + EXAMPLE_BAT+".", SEVERE);
abort;
endif;
// Add a SET PATH command that appends the value of an existing
// search path to C:\EXAPP\BIN.
szPath = "C:\\EXAPP\\BIN;%PATH%";
if (BatchAdd ("PATH", szPath, "PATH", AFTER) < 0) then
MessageBox ("First call to BatchAdd failed", WARNING);
abort;
endif;
// Add the line SET EXENV = C:\OTHERAPP\BIN. If the
// environment variable EXENV already exists in the batch
// file, the last SET EXENV statement is replaced.
szPath = "C:\\OTHERAPP\\BIN";
if (BatchAdd ("EXENV", szPath, "EXENV", REPLACE) < 0) then
MessageBox ("Second call to BatchAdd failed", WARNING);
abort;
endif;
// Add the command SHARE.EXE before the command WIN.
if (BatchAdd ("", "SHARE.EXE", "WIN", BEFORE | COMMAND) < 0) then
MessageBox ("Third call to BatchAdd failed", WARNING);
abort;
endif;
// Save the updated file; back up the original file.
if (BatchFileSave(EXAMPLE_BAK) < 0) then
MessageBox ("Unable to save " + EXAMPLE_BAK + ".", SEVERE);
else
MessageBox ("Batch file saved. Backup created.",INFORMATION);
endif;
end;
InstallShield 2016 Help LibraryMay 2017 |
Copyright Information | Flexera Software |