当前位置: 首页 > 工具软件 > InstallShield > 使用案例 >

installShield_script学习

卓瀚
2023-12-01

20180125

  • script的结构

    包括声明和函数块。声明可以在函数声明之前或者在函数语句和begin语句之间出现。

  • 声明

    每一个脚本都以全局数据声明为开始。此处定义常量(类似于C语言中的宏定义),声明每一个全局变量以及即将使用的用户定义的函数。

    // Constant definitions
    
    #define PRODUCT "InstallShield"
    
    
    #define LIMIT    100
    
    // Variable declarations
      CHAR  cVal;
      NUMBER nVal;
      STRING szName;
    // Function declarations
      prototype DisplayMsg (NUMBER, STRING);
      prototype GetName (BYREF STRING);
  • 函数块

    以prototype语句生命过的所有函数必须在函数块中定义,在endprogram关键字之后

    其他的全局数据声明可以在功能块中,在endprogram语句和第一个函数声明之间或者在函数声明之间进行。 但是,在功能块中声明的数据仅对数据声明后定义的函数可见。

  • 语法符号规则

    分号结尾;

    define and #include 不需要分号结尾;

    关键字诸如program, endprogram, 和begin 等被置于单独行,不需要标点符号;

    函数起始行不需要标点符号;

    标签诸如start: 或者startthere: 以冒号结尾。(目前还没搞懂这里)

    在括号内包含参数列表。用逗号分隔多个参数。

  • 注释

    和C语言一样

  • 空格

    InstallScript 不识别空白字符(spaces and tabs, carriage returns)

  • 匈牙利命名法

    For example, iPointSize denotes an integer variable, while szFileName indicates
    a string variable.

    变量参数命名:第一个字母代表参数类型,v代表必须是变量,不能是常数:szPath可以是字符串常量,而svDir必须是字符串变量。

    详见下表:

    前缀表:

PrefixData TypeWhen Used in Function Syntax
bBoolean (BOOL)Boolean constant, literal, or variable.
bvBoolean (BOOL)Boolean variable only. Constants and literals not allowed.
cCharacter (CHAR)Character constant, literal, or variable.
constConstantConstant or literal. Variables not allowed.
hHandle (HWND)Handle variable.
iInteger (INT)Integer constant, literal, or variable.
lLong integer (LONG)Long integer constant, literal, or variable.
lvLong integer (LONG)Long integer variable only. Constants and literals not allowed.
listList (LIST)List variable.
nNumber (NUMBER)Number constant, literal, or variable.
nvNumber (NUMBER)Number variable only. Constants and literals not allowed.
pPointer (POINTER)Pointer variable.
pstructPointer to a defined structure typeNot used.
sShort integer (SHORT)Short integer constant, literal, or variable.
szString (STRING)String constant, literal, or variable.
svString (STRING)String variable only. Constants and literals not allowed.
structDefined structure typeNot used.

- 转义字符

Escape SequencePerforms the Following Action
\nInserts a line feed.
\’Inserts a single quotation mark in the string.
\”Inserts a double quotation mark in the string.
\rInserts a carriage return only. Does not insert a line feed.
\tInserts a tab character.
\oooIndicates an ASCII character—not an integer—in octal notation.
\Inserts a backslash.

- if语句

c
if (condition) then
// statements to be executed if condition is true
endif;

c
if (FunctionA (ParameterOne) < 0) then
// Statements to handle the failure
else
// Statements when the function succeeds
endif;

  • while语句

    nCount = 1;
    while (nCount < 5)
    MessageBox ("This is still true.", INFORMATION);
    nCount = nCount + 1;
    endwhile;
  • for…endfor

      for j = 20 downto 10 step 5
          MessageBox ("This appears three times.", INFORMATION);
      endfor;
      for iCount = 1 to 10
          MessageBox ("This appears ten times.", INFORMATION);
      endfor;
      for j = 20 downto 10 step 5
          MessageBox ("This appears three times.", INFORMATION);
      endfor;
  • 数据类型

    有的数据类型支持大小写,举例:

    binary
    BINARY

    ​char
    ​CHAR

    ​int
    ​INT

  • 函数

    InstallShield 支持三种函数:

Function TypeDescription
Built-in functionsFunctions supplied by InstallShield or included for Sd dialogs.
User-defined functionsFunctions that you create.
DLL-called functionsFunctions that you can call in a DLL.

重点关注一下dll中的函数调用,dll可以有很大的灵活性。

  • 使用内置函数

    可以在Built-In Functions by Category找到适合需求的函数。

  • minor upgrade制作

    只需要修改product version就可以了;

  • major upgrade制作

    1、版本(major.minor.build.revision)增加(不包括revision)。
    2、UpgradeCode不变。
    3、ProductCode改变。

  • 接收版本号信息

    IS_MAJOR_UPGRADE is an msi property so first you have to fetch it using MsiGetProperty. If that function returns anything, the property is set and it’s a major upgrade

    STRING szPropertyValue;
    NUMBER nSize;
    <hr />
    
    nBufferSize=256;
    MsiGetProperty(ISMSI_HANDLE, "IS_MINOR_UPGRADE", svIsMinorUpgrade,nBufferSize);
    nBufferSize=256;
    MsiGetProperty(ISMSI_HANDLE, "IS_MAJOR_UPGRADE", svIsMajorUpgrade,nBufferSize);
    
    SprintfBox (INFORMATION, "This Works!", "This Installer may be a Minor upgrade - %s",svIsMinorUpgrade);
    
    SprintfBox (INFORMATION, "This Works!", "This Installer may be a Major upgrade - %s",svIsMajorUpgrade);

    或者严谨一点,

    
    nResult = MsiGetProperty ( ISMSI_HANDLE , "IS_MAJOR_UPGRADE" , sUpgrade, nvBufferSize );
    if nResult = ERROR_SUCCESS then
    MessageBox(" update detected ", INFORMATION); 
    MessageBox( sUpgrade, INFORMATION);
    else
    MessageBox(" Not an Update ", INFORMATION);
    endif; 

    ​若需要在Disk中添加新文件或者文件夹,在Supported Files|Advanced Files|Disk中添加。

 类似资料: