The InstallShield script language is similar to C language, and the basic script program framework can be generated by using InstallShield wizards or templates, and can be modified and added according to your own wishes on this basis.
1. Basic grammar rules
1. Variable
BOOL Boolean value is TRUE(1) or FALSE(0)
CHAR Character type One-byte long (8bit) character
HWND The window handle is used to store the window handle
INT Integer two-byte long The integer
LIST list type points to the InstallShield list, use ListCreate and ListDestroy
LONG extended numeric type
LPSTR extended pointer
NUMBER numeric type stores four-byte long values, ranging from -2147483648 to +2147483647
POINTER pointer type
SHORT short value type
STRING string type is very Similar to the LPCTSTR
variable in VC, like the standard C language, it needs to be declared before use. Variables are usually declared in two places, one is outside the main program, such variables are global variables, and the other is the variable declaration area of each function, such variables are local variables.
2. The operators
are generally the same as those of the C language, and will not be explained in detail here. The following mainly introduces the more special operators,
(1) + , - , * , /
The meaning and usage of the above four operators and C language all the same.
(2) &&
and operation, the same as in C language, for example: x1 && x2
(3) ||
or operation, the same as in C language, for example: x1 || x2
(4) !
Non-operation, same as in C language The usage is the same as in C language, for example: !x1
(5) *
Pointer operation, similar to *
(6) & , | , ^ , ~ , << , >> in C language
are bitwise AND, bitwise OR, bitwise XOR, respectively, Bitwise inversion, left shift and right shift, its meaning and usage are basically the same as in C language.
(7) .
This operator is used for structures to get the sub-items of the structure, similar to Delphi's. The usage is similar, for example:
typedef SETTINGSREC
begin
BOOL bSwitchOn;
STRING szMssg[255];
INT nVal;
end;
SETTINGSREC settings;
program
settings .bSwitchOn = FALSE;
settings.szMssg = "Off";
settings.nVal = 0;
(8) =
It can be used both as an assignment number and as an equal sign, for example:
str1 = "String";
if str1="String" then
endif;
(9) &
takes the address character, which is similar to the usage of C language.
(10) < , > , = , <= , >= , !=
represent less than, greater than, equal to, less than or equal to, greater than or equal to, not equal to
(11) + , ^ , %
are used for string operations.
(12) ->
Structure pointer, similar to the usage in C language.
(13) @
is used to get the string defined in the Resource window, for example:
szReferenceFile = svDir ^ @PRODUCT_KEY;
3. The function
of the function InstallShield also needs to be declared before use, and the parameter transfer method of the function is very similar to the C language, such as the following function Declaration :
prototype HandleMoveDataError( NUMBER );
The function name in this declaration is HandleMoveDataError, and a parameter of type NUMBER is passed. When calling this function, it is basically the same as in C language.
The standard format of the function body is:
function functionname(nResult)
// Function variable declaration area
begin
// Program area
end;
the usual function returns a number of type NUMBER.
4. Main program structure The
main program starts with program and ends with endprogram.
2. The basic structure of the framework
program begins with the declaration area of functions and variables.
The framework program established through the wizard includes the following main functions:
prototype ShowDialogs();
// Display the installation wizard dialog
prototype MoveFileData();
// Move file data
prototype HandleMoveDataError( NUMBER );
// Move data error handling
prototype ProcessBeforeDataMove();
// Process before moving file data
prototype ProcessAfterDataMove();
// Move file data Post-processing
prototype SetupRegistry();
// Installation registration, users can add some code here, usually used to operate the registry
prototype SetupFolders();
// Install and generate shortcuts, usually users can add the code to generate shortcuts here
prototype CleanUpInstall();
// Clear temporary files after installation
prototype SetupInstall();
// The actual process of installation
prototype SetupScreen();
// Setup The screen display of the installation process (including background color, font, etc.)
prototype CheckRequirements();
// Check the installation requirements (including hard disk space, operating system platform, etc.)
prototype DialogShowSdWelcome();
// Display the "Welcome" dialog window
prototype DialogShowSdLicense( ); // The dialog prototype
that displays the license information DialogShowSdRegisterUserEx(); // The dialog that displays the user installation registration prototype DialogShowSdAskDestPath(); // The "Installation Path Selection" dialog is displayed prototype DialogShowSdSetupType(); // The "Installation Type" is displayed Selection dialog
prototype DialogShowSdComponentDialog2();
// dialog that displays components for user selection when user selects "custom" installation
prototype DialogShowSdSelectFolder();
// dialog that displays shortcut folder selection
prototype DialogShowSdFinishReboot();
// Display the "installation complete restart" dialog box
programming example:
1. How to display the currently installed file
in the upper left corner of the progress bar Add the following statement
Enable( INDVFILESTATUS ) in function SetupScreen();
2. How to change the window background color
SetColor( BACKGROUND, **** ) function can change the background color of the window, just add it in the appropriate position, where the second variable can be the following values:
BK_BLUE BK_MAGENTA BK_PINK BK_YELLOW
BK_GREEN BK_ORANGE BK_RED The
above are gradient colors
BK_SOLIDBLACK BK_SOLIDMAGENTA BK_SOLIDRED
BK_SOLIDBLUE BK_SOLIDORANGE BK_SOLIDWHITE
BK_SOLIDGREEN BK_SOLIDPINK BK_SOLIDYELLOW
At the same time, the second parameter can also be described by RGB, such as SetColor( BACKGROUND, RGB(0,0,255) )
3. How to create shortcuts in InstallShield5.0 and lower versions
In InstallShield5.1 and higher versions, you can use it in the Resource window If there is a file RegPad.exe (the installation path is selected by the user), add a shortcut to the program in "Start" -> "Program", The specific implementation procedure is as follows:
function SetupFolders()
NUMBER nResult;
STRING svResult,szCommand;
STRING szName;
begin
szName = "RegPad.exe";
szCommand = TARGETDIR ^ szName ;
LongPathToQuote ( szCommand , TRUE );
AddFolderIcon ( FOLDER_PROGRAMS ^"RegPad1.0Beta ","RegPad" ,
szCommand , TARGETDIR , "" , 0 , "" , REPLACE );
4. How to control the user serial number
In the framework program generated by the wizard, a STRING-type global variable svSerial is defined, and at the end of SdRegisterUserEx(), the serial number input by the user will be assigned to the value, and you can judge the variable.
5. How to control restarting the computer
just add the following statement
System ( SYS_BOOTWIN );
6. How to add a statement to Autoexec.bat or Config.sys
The following procedure adds a line of statement to Autoexec.bat
OpenFileMode ( FILE_MODE_APPEND );
OpenFile (nvFileHandle, "C :\\", "Autoexec.bat");
WriteLine ( nvFileHandle , "SET PATH=%PATH%;C:\\ORAWIN95\\BIN" ); 7.
How to allow the user to choose whether to open the Readme file at the end of the installation
The Readme.txt file has been copied to the target path, the following program will display a checkbox, if the user selects it, open Readme.txt with Notepad.
function DialogShowSdFinishReboot()
NUMBER nResult, nDefOptions;
STRING szTitle, szMsg1, szMsg2, szOption1, szOption2,szPathls;
NUMBER bOpt1, bOpt2;
begin
if (!BATCH_INSTALL) then
bOpt1 = TRUE;
bOpt2 = FALSE;
szMsg1 = "";
szMsg2 = "";
szOption1 = "Read the Readme";
szOption2 = "";
nResult = SdFinish( szTitle, szMsg1, szMsg2, szOption1, szOption2, bOpt1, bOpt2 );
if bOpt1 = TRUE then
CopyFile ( "Readme.txt" , "Readme.txt" );
LaunchApp ( WINDIR^"Notepad.exe" , TARGETDIR^"Readme.txt" );
endif;
return 0 ;
endif;
..........
8. How to specify the default path
Modify the following code in function SetupInstall(), such as the default directory to C: \JttMis, see modified code below
if (bIs32BitSetup) then
svDir = WINDISK ^ "Jttmis";
else
svDir = WINDISK ^ "Jttmis"; // use short names
endif;
TARGETDIR = svDir;
The GetProfString() function is a system function for reading the information in the ini file
//The first parameter specifies the path where the file is located
//The second parameter specifies the section name
//The third parameter specifies the keyword name
//The last parameter is used to return the value of the keyword specified earlier. Note: yes return!
//ReplaceProfString() function is a system function, used to modify the value of the keyword in the ini file
//The first parameter specifies the path where the file is located
//The second parameter specifies the section name
//The third parameter specifies the keyword name
//The fourth parameter specifies the original value of the keyword
//The fifth parameter specifies the new value of the keyword
//Only when the first 4 conditions are completely matched, the original value will be replaced by the new value in the fifth parameter
ReplaceProfString (DB_Dir + "my.ini", "mysqld", "basedir", "/"" + DB_Dir + "/"", "/"" + ReplaceStr(DB_Dir) + "/"");
ReplaceProfString (DB_Dir + "my.ini", "mysqld", "datadir", "/"" + DB_Dir + "Data/"", "/"" + ReplaceStr(DB_Dir + "Data") + "/"");
//执行批处理