Fully understand the use of NSIs

Source: Internet
Author: User

The general layout of NSIs is as follows:

  • Preset parameters (including selection of external compressors, compilation options, macro definitions, and file inclusion)
  • General installation settings
  • Custom Functions
  • Installation area content
  • Setup callback functions and related function definitions
  • Uninstall program region content
  • Unmount the program callback function and its related function definitions

A sample script

; Study. NSI; the following script is used to generate the study.exe file; it contains the authorization protocol; if the application is found to be running during installation, the installer prompts and closes the application for the user; the application runs automatically after the installation is successful. Enable the macro command syntax of the new modern UI. Some of the original commands will be disabled to prevent duplication. I will try to demonstrate how to use the basic commands. Of course, macro commands will also be duplicated with some basic commands. re-defining, but NSIs can still be compiled successfully .; you can change some of the paths and files as needed. Enable the external compression tool (we don't need it here, for the reason, see step 2 );! Define have_upx; if the external compression tool is enabled, the file header can be compressed! Ifdef have_upx; Use UPX to compress the executable file header (use other related tools as well )! Packhdr TMP. dat "E: UPX \ UPX -- best TMP. dat "! Endif; Compile option; set the override mark setoverwrite on; set the compression option setcompress auto; select the compression method setcompressor Bzip2; set the data block optimization setdatablockoptimize on; set the data write time setdatesave on; related Data presets; Software name, which is called later by $ {name! Define name "NSIs "! Define name_full "comprehensive understanding of NSIs usage "! Verbose 3; contains the window message definition file! Include "$ {nsisdir} \ examples \ winmessages. nsh"; contains the macro instruction file in the New Territories! Include "$ {nsisdir} \ examples \ modern UI \ modernui. nsh"; contains the macro command file for the signage bitmap! Include "$ {nsisdir} \ examples \ branding. nsh "! Verbose 4! Define currentpage $9! Define temp1 $ R0! Define temp2 $ R1; insert the macro definition on the installation interface (I disabled it here, and it is okay to enable it. Compilation passes. I have defined them later );! Insertmacro mui_interface "modern2.exe" "adni18-installer-C-no48xp.ico" "adni18-uninstall-C-no48xp.ico" "modern.bmp" "smooth"; installer settings; output file OUTFILE "F: \ study.exe "; installer name/lang = 2052 "NSIs"; replace the dialog box style changeui all "$ {nsisdir} \ contrib \ UIS \ modern2.exe"; Enable Windows XP visual style xpstyle on; set the font setfont 9 9; Title name caption/lang = 2052 "Comprehensive NSIs usage"; signage content brandingtext/lang = 2052/trimcenter "Shao Hao"; installer icon ICO N "F: \ 12 \ qcdicon. ICO"; the installer displays the title wicon on; add a tab Bitmap (top parameter is used to place it on the top. Addbrandingimage left 105; sets the gradient background bggradient off; sets the quiet installation mode; silentinstall normal; sets the quiet uninstall mode; silentuninstall normal; executes the CRC Check (preferably on. Close because you need to modify the installer. See step 2) crccheck off; load the corresponding language file loadlanguagefile "$ {nsisdir} \ contrib \ language files \ simpchinese. NLF "; replace the text subcaption/lang = 2052 0 "Authorization protocol" subcaption/lang = 2052 1 "Installation option" subcaption/lang = 2052 2 "installation directory" subcaption/lang = 2052 3 "installing" subcaption/lang = 2052 4 "complete installation "; replace the text of the default button miscbuttontext/lang = 2052 "<previous" "next>" "cancel" "Close"; Replace the text of the "Install" button; installbuttontext/lang = 2052 "installation"; replace the warning when the file cannot be written The text fileerrortext/lang = 2052 "cannot be written to the file $ \ r$ \ N $0 $ \ r$ \ n. Make sure that the file attribute is not read-only and is not in use! "; Default installation directory installdir" $ ProgramFiles \ QCD 3 "; if possible, monitor the installation path from the Registry: installdirregkey HKLM \ "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstall \ NSIs" \ "uninstallstring "; license Agreement page licensetext/lang = 2052 "NSIs is a free software. Before installation, please read the following agreement terms "" I agree "; Use the authorization protocol text licensedata/lang = 2052" F: \ 12 \ license.txt "; set the background color of the authorization Protocol page; licensebkcolor 000000; select the component componenttext/lang = 2052 to be installed. Now, $ {name_full} will be installed on your computer: "" Please select the installation type "" or select the component you want to install "insttype" for full installation (all in) "insttype" typical installation "insttype/lang = 2052/customstring = custom ?; Insttype/lang = 2052/nocustom; insttype/componentsonlyoncustomcheckbitmap "$ {nsisdir} \ contrib \ icons \ modern.bmp"; Replace the text spacetexts/lang = 2052 "required space: "" available space: "; prompt the user to enter the directory text; dirshow hide; Replace the text dirtext/lang = 2052 displayed in the installation directory." select the installation path of $ {name: "" select a directory to install $ {name}: "" Browse... "; whether to allow installation in the root directory allowrootdirinstall false; the color of the installation information; installcolors 000000 ffffff; the installation progress bar display method instprogressflags smooth colored; the installation is automatically disabled after completion The autoclosewindow program is true. The showinstdetails hide dialog box is displayed. Replace the text of the "Show Details" button with detailsbuttontext/lang = 2052 "Show Details "; replace the text completedtext/lang = 2052 "completed" of the "finish" button; uninstall program settings; replace the uninstalltext/lang = 2052 "uninstalltext/lang =" will now be uninstalled from your system $ {name}: "" Uninstall Directory: "; uninstall program icon uninstallicon" F: \ 12 \ unqcdicon. ICO "; replace the uninstallcaption/lang = 2052" Uninstall $ {name} "; replace the uninstallsubcaption/lang = 2052 0" on each page of the uninstaller button ": confirm "uninstallsubcaption/lang = 2 052 1 ": deleting the file" uninstallsubcaption/lang = 2052 2 ": finished"; uninstall the program display mode showuninstdetails hide; replace the uninstallbuttontext/lang = 2052 "Uninstall" text in the uninstallbuttontext/lang = "Uninstall" text, the content of the installation program and its related callback functions, and the content of the installation program section/E "! Main Program (must be installed) "seccoresectionin 1 2 ro; set the output path, change setoutpath $ instdir every time you use it; loop contains all the contents in the directory file/R" F: \ 12 \ 1 \*. * "; contains only one file" F: \ 12 \ gf.gif "; processes the dynamic connection library file iffileexists" $ instdir \ 1.dll" 0 nofile1; cancel component registration unregdll "$ instdir \ 1.dll" Delete" $ instdir \ 1.dll" nofile1: file "F: \ 12 \ 1.dll"; register component regdll" $ instdir \ qcdiconmgr. DLL "; write the software registration key value writeregstr HKLM" SOFTWARE \ NSIs "$ instdir"; write the key value writeregstr HKLM for the Windows uninstall program "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstall \ NSIs" "displayname" "NSIs (only for removal) "writeregstr HKLM" SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstall \ NSIs "" uninstallstring "'" $ instdir \ uninst.exe "'; write the generated uninstall program (multiple times) writeuninstaller "$ instdir \ uninst.exe" sectionendsection/E "extension (optional)" secupdatesectionin 1 setoutpath "$ instdir \ plugins" file "F: \ 12 \ qcdplus \ plugins \ 2.dll" file/R "F: \ 12 \ qcdplus \ plugin S \ 3 "sectionendsubsection/E" option "secoptionssection/E" create desktop icon "secdesktopshortcutsectionin 1 2 setoutpath" $ instdir \ plugins "createshortcut" $ Desktop \ NSIs. lnk "" $ instdir \ gf.gif "writeuninstaller" $ instdir \ uninst.exe "sectionendsection/E" Create a Quick Start bar icon "Secrets 1 2 setoutpath" $ instdir \ plugins "createshortcut" $ quicklaunch \ NSIs. lnk "" $ instdir \ gf.gif "writeuninstaller" $ instdir \ uninst.exe "Sectionendsection/E" create NSIs Program Group "secshortcutgroupsectionin 1 2 setoutpath" $ instdir \ plugins "createdirectory" $ smprograms \ NSIs "createshortcut" $ smprograms \ QCD player \ GF. lnk "" $ instdir \ gf.gif "writeuninstaller" $ instdir \ uninst.exe "sectionendsubsectionendsection"-Run "; run? Execwait '"$ instdir \ 2.exe"-P 'writeinistr" $ instdir \ NSIs. ini "" 2 "" language "" Chinese "EXEC" $ instdir \ 2.exe" execshell open "$ instdir \ .htm" sectionendsection ""; invisible section to display the finish header! Insertmacro mui_finishheader setheadersectionend; the installer initializes and sets the function. oninit; when a program is running, the system prompts to exit and Continues Running loop: findwindow $ R0 "NSIs" intcmp $ R0 0 donemessagebox mb_okcancel \ "NSIs is running. $ \ N click "OK" to close NSIs and continue the installation. Click "cancel" to exit the installer "\ idok noabortabortnoabort: sendmessage $ R0 1029 0; wait a moment and continue detection until the detection fails or the user chooses to cancel sleep 444 goto loopdone:; display the logo image setoutpath $ tempfile/oname1_qcd_logo.bmp "F: \ 12 \ logo.bmp "file/oname=magiclime.exe" $ {nsisdir} \ bin \ magiclime.exe "execwait '" $ Temp \ magiclime.exe "qcd_logo.bmp 'delete" $ Temp \ magiclime.exe "delete" $ temp \ qcd_logo.bmp "; initialize the signage bitmap! Insertmacro bi_init $ r0functionend; function setheader in the main interface of the installation program! Insertmacro mui_header_init! Insertmacro mui_header_start 1! Insertmacro mui_header_text 2052 "Authorization protocol" "Before installing $ {name}, read the authorization terms carefully ."! Insertmacro mui_header_stop 1! Insertmacro mui_header_start 2! Insertmacro mui_header_text 2052 "select component" "select the component you want to install ."! Insertmacro mui_header_stop 2! Insertmacro mui_header_start 3! Insertmacro mui_header_text 2052 "Select installation location" "select an installation directory for $ {name ."! Insertmacro mui_header_stop 3! Insertmacro mui_header_start 4! Insertmacro mui_header_text 2052 "installation" "$ {name} has been installed. Please wait ."! Insertmacro mui_header_stop 4! Insertmacro mui_header_start 5! Insertmacro mui_header_text 2052 "completed" "installation completed successfully ."! Insertmacro mui_header_stop 5! Insertmacro mui_header_endfunctionend; the text function. oninitdialog displayed in the initialization installer dialog box is displayed! Insertmacro mui_innerdialog_init! Insertmacro mui_innerdialog_start 1! Insertmacro mui_innerdialog_text 2052 1040 "if you agree to all the terms in the agreement, select" I am the same "to continue the installation. If you choose" cancel ", the installation will be terminated, only the acceptance terms can be installed $ {name }. "! Insertmacro mui_innerdialog_stop 1! Insertmacro mui_innerdialog_start 2! Insertmacro mui_innerdialog_text 2052 1042 "Description "! Insertmacro mui_innerdialog_text 2052 1043 "Move your mouse over the component to see the description ."! Insertmacro mui_innerdialog_stop 2! Insertmacro mui_innerdialog_start 3! Insertmacro mui_innerdialog_text 2052 1041 "target folder "! Insertmacro mui_innerdialog_stop 3! Insertmacro mui_innerdialog_endfunctionend; processing function. onnextpage when you go to the next page! Insertmacro mui_nextpage_outer! Insertmacro mui_nextpage setheader; signage bitmap settings! Insertmacro bi_nextfunctionend; processing function. onprevpage when you go to the previous page! Insertmacro mui_prevpage; signage bitmap settings! Insertmacro bi_prevfunctionend; the function. onmouseoversection is displayed when the mouse moves to the specified component. Use the macro command to set and install your own annotation text! Insertmacro mui_description_init! Insertmacro mui_description_text 2052 $ {seccore} "Install the main application "! Insertmacro mui_description_text 2052 $ {secupdate} "Install NSIs updates or add plug-ins "! Insertmacro mui_description_text 2052 $ {secoptions} "select other NSIs installation options, such as creating shortcuts and application groups "! Insertmacro mui_description_text 2052 $ {secdesktopshortcut} "create NSIs shortcuts on your desktop "! Insertmacro mui_description_text 2052 $ {secquickbarshortcut} "Create an NSIs shortcut in the user's quick bar "! Insertmacro mui_description_text 2052 $ {secshortcutgroup} "Create a NSIs shortcut group in the user's Start Menu program "! Insertmacro mui_description_endfunctionend; Set function. oninstsuccess after the installation is successful; add it by yourself :) functionend; discard the display information in the warning window during installation function. onuserabort! Insertmacro mui_abortwarning 2052 "are you sure you want to launch the installation of $ {name? "! Insertmacro mui_abortwarning_endfunctionend; List of installation program signage bitmap! Insertmacro bi_list! Insertmacro bi_list_add "F: \ 12 \ brand1.bmp"/resizetofit! Insertmacro bi_list_add "F: \ 12 \ brand2.bmp"/resizetofit! Insertmacro bi_list_add "F: \ 12 \ brand3.bmp"/resizetofit! Insertmacro bi_list_end; uninstall the program and its related callback functions; uninstall the program content section "Uninstall" execwait '"$ instdir \ 12.exe"/UN '; delete Files cyclically until the folder rmdir/R "$ smprograms \ NSIs" unregdll "$ instdir \ 2.dll" Delete" $ instdir \ qcdiconmgr. DLL "delete" $ instdir \*. * "deleteregkey HKLM" SOFTWARE \ NSIs "deleteregkey HKLM" SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstall \ NSIs "MessageBox mb_yesno | mb_iconquestion \" Do you want to delete the plug-in directory? $ \ N (if you want to keep these files, click the "no" button below) "\ IDNO nodelete; all deleted !!! Rmdir/R "$ instdir" nodelete: sectionend; defines the unmount program signage bitmap! Define bi_uninstall! Include "$ {nsisdir} \ examples \ branding. nsh"; initialize the setting function UN. oninit In the uninstall program dialog box; initialize the signage bitmap! Insertmacro bi_init $ r0functionend; uninstall the relevant text function UN. setheader on the main interface of the program! Insertmacro mui_header_init! Insertmacro mui_header_start 1! Insertmacro mui_header_text 2052 "Uninstall $ {name}" "$ {name_full} will be removed from your system ."! Insertmacro mui_header_stop 1! Insertmacro mui_header_start 2! Insertmacro mui_header_text 2052 "Uninstall" "$ {name} is being uninstalled. Please wait ."! Insertmacro mui_header_stop 2! Insertmacro mui_header_start 3! Insertmacro mui_header_text 2052 "finished" "$ {name_full} has been removed from your system ."! Insertmacro mui_header_stop 3! Insertmacro mui_header_endfunctionend; processing function UN. oninitdialog when initializing the uninstalling Program dialog box; add it by yourself: functionend; processing function UN. onnextpage when uninstalling the program to the next page! Insertmacro mui_nextpage_outer! Insertmacro mui_nextpage UN. setheader; tab bitmap settings! Insertmacro bi_nextfunctionend; processing function UN. onuninstsuccess when the uninstalling program is complete; adding handler _^ functionend; discarding the processing function UN. onuserabortfunctionend when the uninstalling program is complete; uninstalling the program signage bitmap list! Insertmacro bi_list! Insertmacro bi_list_add "F: \ 12 \ unbrand1.bmp"/resizetofit! Insertmacro bi_list_add "F: \ 12 \ unbrand2.bmp"/resizetofit! Insertmacro bi_list_end; End


; Source: http://haijd.net/article/index.php? Action = read & id = 516

Related Article

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.