Chinaunix首页 | 论坛 | 博客
  • 博客访问: 588273
  • 博文数量: 208
  • 博客积分: 3286
  • 博客等级: 中校
  • 技术积分: 1780
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-24 20:38
文章分类

全部博文(208)

文章存档

2012年(7)

2011年(28)

2010年(21)

2009年(76)

2008年(65)

2007年(11)

我的朋友

分类:

2009-03-27 18:34:13

 
PreviousNext
Help Library

BatchAdd

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.

Syntax

BatchAdd ( szKey, szValue, szRefKey, nOptions );

Parameters

BatchAdd Parameters 

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.

Caution

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:

  • BEFORE—The statement is added before the first line that contains szRefKey. If szRefKey is a null string (""), the statement is added as the first line of the file.
  • AFTER—The statement is added after the last line that contains szRefKey. If szRefKey is a null string (""), the statement is added as the last line of the file.
  • REPLACE—The statement replaces an existing line in the file. If multiple lines with same key exist, only the last line is replaced. If szKey does not exist in the file, a new line will be added after szRefKey. If szRefKey is a null string (""), the new line is added as the last line of the file.

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);

Note

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 Values

BatchAdd Return Values 

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.

Additional Information

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
 | 
 
 
 
 
 
 
 
 
 
 
 
 
PreviousNext
Help Library

BatchAdd Example

InstallShield 2009 » 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

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;

阅读(1157) | 评论(0) | 转发(0) |
0

上一篇:AskYesNo

下一篇:BatchDeleteEx

给主人留下些什么吧!~~