A complete InstallShield installer instance-goddess of the sea of azelas (3)-advanced settings 1

Source: Internet
Author: User
Original article: a complete InstallShield installer instance-goddess of the sea of azelas (3)-advanced settings 1

Previous Article: a complete installer instance-goddess of the sea of azelas (2)-Basic settings 2

Part 2: Script Programming

Before starting programming, let's clarify which functions we have set up earlier to use programming.

1. display software license agreement

2. check whether the required prerequisite software jkd1.6.0 _ 04 is installed. If not, start the external installer for installation. (The same principle can be used to determine whether other software is installed, as long as the software has a key value in the Registry)

3. the user input information, the selected installation path, and the selected installation components are displayed on the installation interface (although InstallShield comes with this interface, it is blank by default, you need to write scripts to display information)

4. Copy the corresponding files from the external folder to the folder in the target installation path based on the selected components.

5. Create a shortcut Based on the files copied from the external. (copy the document and create a shortcut in the Start Menu)

6. The readme.txt file is displayed during the installation of the hosts file.

7. Start the specified program after installation.

8. Perfect uninstall

Script Programming is performed on the installer designer interface. I will not go into details later.

Installshield is case-sensitive. Therefore, follow the case-sensitive rules in the example. For example, string and string variables are supported, but string does not. 1. display software license agreement

1. Add license agreement text

Find the behavior and logic | Support files/Billboards option in the left-side navigation tree. This option allows you to add files required during installation.

Corresponding options are displayed in the middle navigation bar.

Under the Support files branch, a language independent and all your selected language types are displayed. Language independent indicates that, if you set the branch here, this setting will take effect no matter which language you choose to install it. The language type indicates that, if you set a language, this setting takes effect only when you select to install it in this language.

Click language independent. This time, we will test it under this branch.

Right-click the files column on the right and select insert files from the pop-up menu.

Select a text file of the license agreement you have prepared and insert it to the files column.

The license agreement supports two text formats: TXT and RTF. Here we use TXT.

2. Switch to behavior and logic | installscript option,

3. There is a default rul file setup. rul under files in the middle navigation bar. All the installscript code of this project will be written in this default file.

4. Click the select setup. rul node. The programmable Panel of the file is displayed on the right.

5. The license agreement should be displayed at the beginning of running the installer, that is, before the data is copied. Select the before move data option in the first drop-down box, and then select the onbegin option in the second drop-down box (do not display these two options by default, if you do not select the option from the drop-down list, or the software fails to detect the option you selected and the Code cannot be automatically added, some code is automatically added to the programming interface, as shown in. Of course, you can also press the code manually.

6. we will write code in the function body of function onbegin () to display the content of the added license agreement text, and directly copy the following code to the begin and end of the onbegin () function; between.

Disable (backbutton );

If (! Maintenance) then

Sdlicense2 ("License", "", "", suppdir dir ^ "2.txt", false );

Endif ;.

7. Code explanation

**************************************** ********************************

Disable (backbutton );

Set the previous button to unavailable. The installer has a default start interface at the beginning, and the license agreement is displayed in the second step. In general, there is no need to go back and check that there is nothing to do with the start interface, therefore, set the rollback button to unavailable.

**************************************** ********************************

If (! Maintenance) then

Endif;

This condition is used to determine the status of the installation program, including installation, repair, Reinstallation, and uninstallation. The last three conditions are in the maintenance status. Therefore, the license agreement is displayed only when the installation is normal.

**************************************** ********************************

Sdlicense2 ("License", "", "", suppdir dir ^ "2.txt", false );

This function is used to display the license agreement used on the interface. The constructor for this function in help is as follows:

Sdlicense2 (sztitle, szopt1, szopt2, szlicensefile, blicenseaccepted );

Parameter 1: sztitle, the title displayed in the upper-left corner of the interface. If you enter an empty string "", it is displayed as the default value "License Agreement ".

Parameter 2: szopt1. There are two options on our common License Agreement interface: "agree" and "disagree". szopt1 and szopt2 are the two options, if an empty string is entered, the default values "I accept the terms of the license agreement" and "I do not accept the terms of the license agreement" are displayed ".

Parameter 3: szopt2. For details, see parameter 2.

Parameter 4: szlicensefile, which specifies the document to be displayed, including the path and document name with the extension. . The path caused by static variable paths and quotation marks is connected with the ^ symbol.

Parameter 4: blicenseaccepted, Boolean variable, true state. The "agree" option is selected by default on the license agreement interface; however, it seems that the option "disagree" is selected by default, so you can enter "false" here.

This is the license agreement interface. After you select the I accept the terms of the license agreement option, the next button is available and the installer can continue. (Ignore the license agreement content shown here... There are many software license agreement templates for download on the internet ...)

Summary: Now, the license agreement has been added. during installation and execution, the user can see that the license agreement is displayed on the interface, and only after the "agree" option is selected, the installation program will be executed.

The function that displays the license protocol has three sdliclicenses, sdlicensertf and sdlicense2. The parameters are slightly different and the displayed interface is slightly different. You can choose from them based on your preferences. Currently, sdlicense2 is commonly used. The displayed interface conforms to the most popular installation interface habits. 2. Determine whether the required prerequisite software or runtime environment is installed.

1. The code is still implemented in the onbegin () function. You can directly copy the following code to the begin and end of the onbegin () function.

Regdbsetdefaultroot (HKEY_LOCAL_MACHINE );

If (regdbkeyexist ("Software \ mongooft \ Java Development Kit \ 1.6.0 _ 04") <0) then

Launchappandwait (srcdisk ^ "JDK \ jdk-6u4-windows-i586-p.exe", "", laaw_option_wait );

Endif;

2. Code explanation

**************************************** ********************************

Regdbsetdefaultroot (HKEY_LOCAL_MACHINE );

Set the root node of the default registry key value to HKEY_LOCAL_MACHINE.

Open the registry and you will see hkey_classes_root, HKEY_CURRENT_USER, and HKEY_LOCAL_MACHINE at the root nodes under "my computer. The registry key value of the JDK software we are looking for this time is under HKEY_LOCAL_MACHINE, so we need to set the root key to HKEY_LOCAL_MACHINE.

The table tells me that you do not know how to view the registry, start-> Run-> enter the command regedit

**************************************** *******************************

Regdbkeyexist ("Software \ mongooft \ Java Development Kit \ 1.6.0 _ 04") <0)

Check whether the key value Software \ javasoft \ Java Development Kit \ 1.6.0 _ 04 exists. This is the value written to the Registry during jdk1.6.0 _ 04 Installation;

Regdbkeyexist (szsubkey); If a key value exists, 1 is returned; otherwise, a random number smaller than 0 is returned.

**************************************** *******************************

Launchappandwait (srcdisk ^ "JDK \ jdk-6u4-windows-i586-p.exe", "", laaw_option_wait );

Installer.

This function is described in help as follows:

Launchappandwait (szprogram, sz1_line, noptions );

Parameter 1: szprogram, that is, the program to be started. Here we write parameters srcdisk ^ "JDK \ jdk-6u4-windows-i586-p.exe", srcdisk refers to the source disk, the installation program in the disk, the disk and hard disk can be. The jdk-6u4-windows-i586-p.exe installer under the JDK \ jdk-6u4-windows-i586-p.exe source.

Parameter 2: szcmdline. If the program to be started needs to read parameters from the command line to start the program, write the corresponding parameter value here; we do not need this, So enter an empty string "".

Parameter 3: noptions, static variables, different static variables will get different execution results, such as no waiting for installation, silent installation, and Mouse shape change. For more information, see the help provided by InstallShield. Here we use laaw_option_wait, that is, after the JDK installation is complete (whether it is a normal installation or the user clicks to cancel the installation), the installation program continues.

You can see that when you click agree to the license agreement, the installer automatically checks whether JDK is installed. If not, the installation interface is displayed.

In the function body, no judgment is made on the failure to find the JDK installer and installation errors. If necessary, you can add a message box prompting you to manually install the required software if the installation program cannot be found or the installation fails. Code can be rewritten

Regdbsetdefaultroot (HKEY_LOCAL_MACHINE );

If (regdbkeyexist ("Software \ mongooft \ Java Development Kit \ 1.6.0 _ 04") <0) then

If (launchappandwait (srcdisk ^ "JDK \ jdk-6u4-windows-i586-p.exe", "", laaw_option_wait) <0) then

MessageBox ("You haven't installed JDK 1.6.0 _ 04 yet! ", Information );

Endif;

Endif;

Conclusion: At this point, the function of the software required for running has ended. You can test multiple software by yourself. The usage is to repeat the above Code function and it is still executed in the onbegin () function. 3. the user input information, the selected installation path, and the selected installation components are displayed on the installation interface.

InstallShield comes with this interface. You can see this interface during the installation process, but the information on this interface is empty, which is confusing and suspected to be a bug of InstallShield. Therefore, we have to manually implement this function.

1. This function needs to be implemented in the onfirstuibefore () function body. Select the before move data | onfirstuibefore option.

2. After this option is selected, the software will automatically generate a large amount of code on the programming interface. Each dlg_sdxxxx corresponds to an interface. For example, dlg_sdwelcome corresponds to the welcome interface at the beginning. If developers are familiar with these features, you can program each interface here.

3. Find the interface option dlg_sdstartcopy. Here we will modify the existing code to display user information, the selected installation path, and components.

4. Define the required variables first.

Define six feature names and two number-type variables before in, that is, the blue string. Previously, we defined six available feature items in the first part. Here we need to make some judgments on these six feature items.

Assign values to these six feature values after in. the value assigned is the name (name, not display name) of the feature defined in the first part ).

//---------------------------------------------------------------------------

Function onfirstuibefore ()

Number nresult, nsetuptype, nvsize, nuser;

String sztitle, szmsg, szquestion, svname, svcompany, szfile;

String szlicensefile;

List list, liststartcopy;

Bool bcustom;

String szfeaturename1;

String szfeaturename2;

String szfeaturename3;

String szfeaturename4;

String szfeaturename5;

String szfeaturename6;

Number bvopt1, bvopt2;

Begin

// To do: If you want to enable background, window title, and caption bar title

// Settitle (@ product_name, 24, white );

// Settitle (@ product_name, 0, backgroundcaption );

// Enable (fullwindowmode );

// Enable (background );

// Setcolor (background, RGB (0,128,128 ));

Szfeaturename1 = "server ";

Szfeaturename2 = "client ";

Szfeaturename3 = "watch_portion ";

Szfeaturename4 = "log_portion ";

Szfeaturename5 = "report_portion ";

Szfeaturename6 = "document ";

5. nresult = sdstartcopy (sztitle, szmsg, liststartcopy) between liststartcopy = listcreate (stringlist); and listdestroy (liststartcopy); added the following code before.

Listaddstring (liststartcopy, "customer information:", after );

Listaddstring (liststartcopy, "User name:" + svname, after );

Listaddstring (liststartcopy, "company name:" + svcompany, after );

Listaddstring (liststartcopy, "Destination location:" + installdir, after );

Switch (nsetuptype)

Case typical: listaddstring (liststartcopy, "setup type: Typical", after );

Case compact: listaddstring (liststartcopy, "setup type: Compact", after );

Case custom: listaddstring (liststartcopy, "setup type: Custom", after );

Endswitch;

Listaddstring (liststartcopy, "", after );

Listaddstring (liststartcopy, "the selected feature:", after );

If (featureisitemselected (Media, szfeaturename1) = 1) then

Listaddstring (liststartcopy, "" + szfeaturename1, after );

Endif;

If (featureisitemselected (Media, szfeaturename2) = 1) then

Listaddstring (liststartcopy, "" + szfeaturename2, after );

Endif;

If (featureisitemselected (Media, szfeaturename3) = 1) then

Listaddstring (liststartcopy, "" + szfeaturename3, after );

Endif;

If (featureisitemselected (Media, szfeaturename4) = 1) then

Listaddstring (liststartcopy, "" + szfeaturename4, after );

Endif;

If (featureisitemselected (Media, szfeaturename5) = 1) then

Listaddstring (liststartcopy, "" + szfeaturename5, after );

Endif;

If (featureisitemselected (Media, szfeaturename6) = 1) then

Listaddstring (liststartcopy, "" + szfeaturename6, after );

Endif;

6. Code explanation

**************************************** *********************

Listaddstring (liststartcopy, "xxxxxx", after );

Add the information to be displayed to the list. The content of this list will be added to the interface for display later.

In help, this function is described as follows: listaddstring (listid, szstring, nplacementflag );

Parameter 1: listid. You need to create a list in advance. here we can see that liststartcopy = listcreate (stringlist); this statement creates a list called liststartcopy.

Parameter 2: szstring, the string to be added

Parameter 3: nplacementflag. If it is set to after, it is added in sequence. If it is before, it is added in reverse order, that is, the newly added content is displayed in front.

**************************************** *********************

Switch (nsetuptype)

Case typical: listaddstring (liststartcopy, "setup type: Typical", after );

Case compact: listaddstring (liststartcopy, "setup type: Compact", after );

Case custom: listaddstring (liststartcopy, "setup type: Custom", after );

Endswitch;

This displays the installation type information based on the selected installation type. There are three installation types: Typical, compact, and custom.

**************************************** *********************

If (featureisitemselected (Media, szfeaturename1) = 1) then

Listaddstring (liststartcopy, "" + szfeaturename1, after );

Endif;

Here featureisitemselected (Media, szfeaturename1) = 1 is a very important function that will appear multiple times in this installer. This function is used to determine whether a user selects a feature. In help, this function is described as follows: featureisitemselected (szfeaturesource, szfeature );

Parameter 1: szfeaturesource, which seems to be the source of feature, but does not quite understand what it actually refers to. It is not wrong to copy the media file in the example provided by help.

Parameter 2: szfeaturename1, that is, the feature name.

If you select this feature, the returned value is 1, and you can add information about the feature to the list.

After repeated attempts, you can determine whether all feature items are selected. if selected, you can add relevant information.

This displays the user information, installation path, and installation component information. If the above Code is not added, the interface is displayed by default, but the information bar is blank.

By the way, when I used to create this installer, it was blank because it was blank. At that time, I knew nothing about programming. In a hurry, the display setting box is invisible. The setting method is as follows:

Find User Interface | dialogs

Find the sdstartcopy option in the navigation tree in the middle.

Here we use the English interface, so click to select the English option

Select the user information box on this interface and set the visible option on the right to false.

Summary: In the dlg_sdstartcopy interface, you can also set the title and message displayed in the upper left corner, sztitle = ""; szmsg = ""; if the values of the two lines of code are null, the default information displayed. You can assign a value to the information you want to display.

Next article: a complete installer instance-goddess of the sea of azelas (4)-Advanced Settings 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.