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必須是字符串變量。
詳見下表:
前綴表:
Prefix | Data Type | When Used in Function Syntax |
---|---|---|
b | Boolean (BOOL) | Boolean constant, literal, or variable. |
bv | Boolean (BOOL) | Boolean variable only. Constants and literals not allowed. |
c | Character (CHAR) | Character constant, literal, or variable. |
const | Constant | Constant or literal. Variables not allowed. |
h | Handle (HWND) | Handle variable. |
i | Integer (INT) | Integer constant, literal, or variable. |
l | Long integer (LONG) | Long integer constant, literal, or variable. |
lv | Long integer (LONG) | Long integer variable only. Constants and literals not allowed. |
list | List (LIST) | List variable. |
n | Number (NUMBER) | Number constant, literal, or variable. |
nv | Number (NUMBER) | Number variable only. Constants and literals not allowed. |
p | Pointer (POINTER) | Pointer variable. |
pstruct | Pointer to a defined structure type | Not used. |
s | Short integer (SHORT) | Short integer constant, literal, or variable. |
sz | String (STRING) | String constant, literal, or variable. |
sv | String (STRING) | String variable only. Constants and literals not allowed. |
struct | Defined structure type | Not used. |
- 轉義字符
Escape Sequence | Performs the Following Action |
---|---|
\n | Inserts a line feed. |
\’ | Inserts a single quotation mark in the string. |
\” | Inserts a double quotation mark in the string. |
\r | Inserts a carriage return only. Does not insert a line feed. |
\t | Inserts a tab character. |
\ooo | Indicates 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
BINARYchar
CHARint
INT函數
InstallShield 支持三種函數:
Function Type | Description |
---|---|
Built-in functions | Functions supplied by InstallShield or included for Sd dialogs. |
User-defined functions | Functions that you create. |
DLL-called functions | Functions 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中添加。