The previous article mentioned InstallShield to quickly create a package. Now let's talk about the installscript script in InstallShield. This article is personal understanding. For more information, see related articles.
Related materials: http://download.csdn.net/detail/iamdale11/8104971
This document includes the InstallShield internal library functions and an understanding of the dialog
First, click installation designer based on the previous article.
Click installscript below.
Click setup. rul first, and then select before move data and onfirstuibefore. The program source code quickly packaged in the previous article is displayed in the setup. rul file.
1. During installation, enter the serial number and add the following code in the Custom process:
Dlg_sdregisteruserex: // tag
Szmsg = ""; // Information Field
Sztitle = ""; // Title
Szserial = ""; // serial number
Disable (backbutton); // hide the return button
Nresult = sdregisteruserex (sztitle, szmsg, szname, szcompany, szserial); // call the library function to display the corresponding Dialog
// Determine whether the serial number is correct
If (szserial! = '000000') then
MessageBox ("Warning: The Input Serial number is incorrect. Please confirm and try again! ", Severe );
Goto dlg_sdregisteruserex;
Endif;
If (nresult = back) goto dlg_sdwelcome;
2. During the installation process, you need to check the environment of the installation program. Add the following code where you need to check:
Regdbsetdefaultroot (HKEY_LOCAL_MACHINE); // obtain the HKEY_LOCAL_MACHINE value in the registry.
If (regdbkeyexist ("SOFTWARE \ Microsoft \ Net Framework Setup \ NDP \ v4.0") <0) Then // checks whether the corresponding environment exists. Here is. Net 4.0
MessageBox ("the corresponding runtime environment is not installed and is being installed", warning );
// Launchappandwait (srcdisk ^ "1233456789.exe"," ", laaw_option_wait); // call related programs on the corresponding disk for installation.
Goto dlg_sdlicense2;
Else
MessageBox ("the corresponding environment has been installed", warning );
Endif;
3. Custom Dialog
For example, click "dialog" and Right-click "new dialog" on "all dialog. Create a custom dialog.
Then, right-click files to create a new. rul file and create the corresponding dialog file.
For example, the code in the selectdlg. rul file is as follows:
// Macro-defined correlation. Note: to obtain the relevant features on the dialog form, you need to extract the values in the control identifier of the relevant features.
# Define dlg_selectdlg "selectdlg"
# Define gengxin 1322
# Define anzhuang 1323
# Define nextbtn 1
# Define backbtn 12
Prototype selectdlg (byref string, byref string); // define a method
Function selectdlg (sztitle, szmsg)
// Define related variables
Number NID, nresult, szggzz, sztest;
Hwnd hwnddlg;
Bool bdone;
String szgz1, szgz2, szte;
Begin
// Specify a name to identify the custom dialog in this installation.
// Ensure general Initialization is complete
If (! Bsdinit) then
Sdinit ();
Endif;
// Declare a form
Nresult = ezdefinedialog (dlg_selectdlg, isuser, "selectdlg", 0 );
// MessageBox (szgz, warning );
// Initialize the indicator used to control the while loop.
Bdone = false;
// Loop until done.
While (! Bdone)
// Display the dialog and return the next dialog event.
Nid = waitondialog (dlg_selectdlg); // display a form
// Respond to the event.
Switch (NID)
Case dlg_init: // operations related to form Initialization
Ctrlsetstate (dlg_selectdlg, anzhuang, button_checked );
// No Initialization is required for this example.
Case nextbtn: // click Next
// Getctrltext ();
If (ctrlgetstate (dlg_selectdlg, gengxin) = button_checked) Then // determine whether the radio button is selected
Nid = next;
Endif;
If (ctrlgetstate (dlg_selectdlg, gengxin) = button_checked) then
Nid = custom;
Endif;
Bdone = true;
Case back: // return button
Nid = back;
Bdone = true;
Case dlg_err:
Sderror (-1, "errrrrrrr ");
Nid =-1;
Bdone = true;
Case dlg_close:
Sdclosedlg (hwnddlg, NID, bdone );
Default:
// Check standard handling
If (sdisstdbutton (NID) & sddostdbutton (NID) then
Bdone = true;
Endif;
Endswitch;
Endwhile;
// Cleanup Dialog
Enddialog (dlg_selectdlg); // end form
Releasedialog (dlg_selectdlg); // release the form
Sduninit ();
// Record data produced by this dialog
If (mode = recordmode) then
Endif;
Return NID;
End;
4. file copy operations
Varsave (srctargetdir); // save the system variable value
Srcdir = strjq; // strjq is the path string, which stores the corresponding path
Targetdir = svdir; // svdir is the path string, which stores the corresponding path
Nresult = copyfile ("*. *", "*. *"); // copy the operation. For details, refer to database function introduction.
Varrestore (srctargetdir); // restore the default source folder and target folder path
5. Button verification function. For details, refer to the custom dialog in the document.
Function checkinputvalid (hwnddlg, ballownotset)
String szinputadd;
Begin
If (ballownotset) then
_ Winsubenablecontrol (hwnddlg, sd_pbut_continue, 1 );
Return 1;
Endif;
Ctrlgettext (dlg_gxdlg, svdir, szinputadd );
If (strlength (szinputadd) = 0) then
_ Winsubenablecontrol (hwnddlg, sd_pbut_continue, 0 );
Return 0;
Endif;
_ Winsubenablecontrol (hwnddlg, sd_pbut_continue, 1 );
Return 1;
End;
This is what I think. Please make mistakes and discuss them with each other.
Installscript programming in InstallShield