1. Create an InstallOption file in HM VNISEdit 2.0.3 and add corresponding controls through the graphic interface.
Note: state is the displayed text or value, and Flags is operation-related. values must be written if there is an event. The interface is as follows:
The Code is as follows:
; Ini file generated by the hm nis Edit IO designer. [Settings] NumFields = 8 [Field 1] Type = GroupboxText = connect to SQL ServerLeft = 0 Right = 300Top = 0 Bottom = 86 [Field 2] Type = TextState = saLeft = 55 Right = 282Top = 40 Bottom = 52 Flags = WANTRETURN [Field 3] Type = PasswordState = saLeft = 55 Right = 282Top = 60 Bottom = 75 Flags = WANTRETURN [Field 4] Type = LabelText = Login Name: left = 19 Right = 51Top = 44 Bottom = 52 [Field 5] Type = LabelText = password: Left = 19 Right = 51Top = 65 Bottom = 75 [Field 6] Type = ButtonText = test connection Left = 0 Right = 299Top = 92 Bottom = 108 Flags = Policy [Field 7] Type = LabelText = Server: left = 19 Right = 51Top = 25 Bottom = 35 [Field 8] Type = TextFlags = READONLYState = local server Left = 56 Right = 282Top = 22 Bottom = 35 2. Place the interface after the welcome page, the Code is as follows:; ------ user-defined page ------ Var hwnd; user-defined page window handle Var SQL _SERVERNAME # server name for example: server; user5 ...... it is usually the computer name Var SQL _LOGINNAME # the login name, for example, sa ..... SQL Server Security Attribute usage Account name Var SQL _LOGINPASSWORD # login password. If you use sa to log on, the sa password Var SQL _isql_DIR # isql.exe is required here. Welcome to the page! Insertmacro MUI_PAGE_WELCOMEPage custom PageInitFunc PageLeaveFunc # custom page. Here is the initialization method, the method when it leaves, and the installation process page! Insertmacro MUI_PAGE_INSTFILES; installation completion page! Define MUI_FINISHPAGE_RUN "$ INSTDIR \ YHK2005.exe "! Insertmacro MUI_PAGE_FINISH; installation and uninstallation process page! Insertmacro MUI_UNPAGE_INSTFILES; language settings included in the installation interface! Insertmacro MUI_LANGUAGE "SimpChinese"; here is the generated code (non-custom Interface) name "$ {PRODUCT_NAME }$ {PRODUCT_VERSION}" OutFile "contains multiple install_name1_.exe" InstallDir "$ {INSTALL_DIR}" ShowInstDetails showuninstdetails showBrandingText "$ {INSTALL_WATER }"; ------ custom page ------ ReserveFile "$ {NSISDIR} \ Plugins \ InstallOptions. dll "ReserveFile" C: \ Documents and Settings \ Administrator \ Desktop \ Link2SQL. ini "Uninstall install .exe the executable file you want to detect Function. onI Nit; ------ custom page ------ InitPluginsDir File/oname = $ PLUGINSDIR \ Link2SQL. ini "C: \ Documents ents and Settings \ Administrator \ Desktop \ Link2SQL. ini "FunctionEnd Function PageInitFunc SendMessage $ HWNDPARENT $ {WM_SETTEXT} 0" STR: Database Configuration "! Insertmacro MUI_HEADER_TEXT "connect to Database" to perform database-related operations. You need to log on to the database username and password ". Set the page header GetDlgItem $0 $ HWNDPARENT 1 EnableWindow $0 through the macro MUI_HEADER_TEXT; in the registry, read the computer name ReadRegStr $ SQL _SERVERNAME HKLM "SYSTEM \ CurrentControlSet \ Control \ ComputerName" "ComputerName" WriteINIStr "$ PLUGINSDIR \ Link2SQL. ini "" Field 8 "" State "" $ SQL _SERVERNAME "InstallOptions: initDialog/NOUNLOAD" $ PLUGINSDIR \ Link2SQL. ini "Po P $ hwnd; get the window handle InstallOptions: show on the custom page. Pop $0 FunctionEnd Function PageLeaveFunc ReadINIStr $0 "$ PLUGINSDIR \ Link2SQL is displayed. ini "" Settings "" State "; reading the control using state is the ordinal number after Field StrCmp $0 0 NextBtn; click Next To StrCmp $0 6 TestLinkBtn; click the test connection button-6 is the control's FieldNum Goto NextBtn TestLinkBtn: ReadINIStr $ SQL _LOGINNAME "$ PLUGINSDIR \ Link2SQL. ini "" Field 2 "" State "; get the username status ReadINIStr $ SQL _LO GINPASSWORD "$ PLUGINSDIR \ Link2SQL. ini "" Field 3 "" State "; get the password status ReadRegStr $ SQL _isql_DIR HKLM" SOFTWARE \ Microsoft SQL Server \ 80 \ Tools \ ClientSetup "" SQLPath "nsExec :: execToStack '"$ SQL _isql_DIR \ Binn \ isql"-S $ SQL _SERVERNAME-U $ SQL _LOGINNAME-P $ SQL _LOGINPASSWORD-Q "select' OK '"-o $ PLUGINSDIR \ result.txt' # Here is only if the return value of $0 is 0, the connection passes, if it is another value, a connection error occurs, proving that the input of parameters such as the account and password is incorrect. This is a simple check. A safer operation is to read result.txt. File. If the 3rd rows are displayed as OK, the connection is normal and an SQL statement is run smoothly. Pop $0 StrCmp $0 0 passMessageBox MB_ OK "connection error. Enter the connection information again. Otherwise, subsequent operations cannot be performed! "Abortpass: MessageBox MB_ OK" connection successful! "GetDlgItem $0 $ HWNDPARENT 1 EnableWindow $0 1 Abort; do not enter the next page, because the next button NextBtn: FunctionEnd is not clicked: Click test connection, after the connection is correct, it can be used for intermittent installation.