分类:
2009-03-27 18:34:13
InstallShield 2009 » InstallScript Language Reference
The BatchAdd function inserts a SET command or other DOS command into a batch file that has been loaded into memory with . The parameter nOptions allows you to add the new command as the first or last statement in the file, replace an existing statement with the new command, or specify that the new command be added before or after an existing statement.
Before calling BatchAdd, you must call BatchFileLoad to load the file to be modified into memory. After you modify the file, call to save it to disk.
Do not mix the Ez batch file functions with the advanced batch file functions. After calling BatchFileLoad, you cannot use Ez batch file functions until you have called BatchFileSave to save the file.
BatchAdd ( szKey, szValue, szRefKey, nOptions );
Parameter |
Description |
---|---|
szKey |
Specifies the keyword to add to the batch file. PATH, TEMP, and MYENV are examples of valid keys for this parameter. |
szValue |
Specifies the value of the key to be added to the batch file. This string must be no longer than 512 bytes; passing a string longer than 512 bytes will cause an installation error. To add a longer string, use the and functions. Batch files do not support long paths completely. If you are using this function to add a line that contains a long path, call to convert the long path to its short path equivalent before adding it to the string to be placed in the batch file. For information on long paths and long file names, refer to Long File Name Format. |
szRefKey |
Specifies the reference key relative to which you are adding szKey in the batch file. |
nOptions |
Specifies where in the file to insert the line. Pass one of the following predefined constants in this parameter:
When the statement to be added is not a SET command, pass a null string ("") in szKey, pass the complete command in szValue, and use the OR operator to combine the constant COMMAND with one of the other option constants, as shown below: BatchAdd("", "PAUSE", "", COMMAND | AFTER); BatchAdd automatically adds the DOS keyword SET to the beginning of the statement to be inserted unless you use the OR operator to combine the constant COMMAND with the value you pass in nOptions. If you do not explicitly specify REPLACE in nOptions, the specified statement is added even if a duplicate line exists in the batch file. |
Return Value |
Description |
---|---|
0 |
BatchAdd successfully added a SET statement or other command to the batch file. |
< 0 |
BatchAdd was unable to add the SET statement or other command to the batch file. |
An InstallScript reference key is either an environment variable, a DOS command, or a program file name. Environment variables are keywords such as PATH, COMSPEC, LIB, or other predefined or user-defined identifiers. The value of an environment variable is established by using the DOS SET command. Statements that appear in a batch file must be either DOS commands, program names (with or without command-line parameters), or comments. Refer to your operating system manual for a detailed definition of commands and environment variables.
See Also
InstallShield Help Library 5 June 2008 | | |
Popup | ||||
InstallShield 2009 » InstallScript Language Reference
The following example applies to:
/*-----------------------------------------------------------*\
*
* 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:
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;