nsis tutorial
DESCRIPTION
Presentation...TRANSCRIPT
![Page 1: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/1.jpg)
NSIS - TutorialNullsoft Scriptable Install System
"An installer is the first experience of a user with your application. Slow or unsuccessful software installations
are the most irritating computer problems.“ [http://nsis.sourceforge.net/home/]
David Schwingenschuh (BSc)
![Page 2: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/2.jpg)
Agenda
• Introduction
• Scripting Structure– Installer Attributes– Pages– Sections– Functions– Compiler Commands
• Debugging Scripts
![Page 3: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/3.jpg)
Agenda
• Development Tools
• NSIS Framework
• Installer Example
• Appendix A: Detailed features
![Page 4: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/4.jpg)
Introduction
• NSIS creates installers that are capable of – installing, – uninstalling, – setting system settings, – extracting files, etc.
• you can fully control every part of your installers. – based on script files
![Page 5: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/5.jpg)
Introduction
• The script language supports – variables, – functions, – string manipulation
• NSIS is still the smallest installer system available. – (With the default options, it has an overhead of
only 34 KB.)
A detailed overview about the functions can be found at Appendix A
![Page 6: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/6.jpg)
Introduction
• Download NSIS from:– http://nsis.sourceforge.net/download/
• Installation of nsis-version.exe
• NSIS Welcome Screen
Setting up NSIS Environment
![Page 7: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/7.jpg)
Introduction
• NSIS Quick start Installer– Go to the examples folder under the nsis
installation directory
– Choose one .nsi file with a right mouse click and press compile NSIS Script
– The choosen script will be automatically compiled
– Press on Test Installer -> Congratulations you have successfully compiled your first NSIS Installer
Setting up NSIS Environment
![Page 8: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/8.jpg)
Introduction
– The choosen script will be automatically compiled
– Press on Test Installer -> Congratulations you have successfully compiled your first NSIS Installer
Setting up NSIS Environment
![Page 9: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/9.jpg)
Introduction
• A Script file is the basis for NSIS
– It is recommended to use editor that shows line numbers
– Editors which supports syntax highlighting for NSIS scripts can be found at http://nsis.sourceforge.net/wiki/
Script Files
![Page 10: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/10.jpg)
Introduction
• In a NSIS script every line is treated as a command.
• If your command is too long for one line – you can use a back-slash - '\' - at the end of the
line..
For example:Messagebox MB_OK|MB_ICONINFORMATION \
"This is a sample that shows how to use line breaks for larger commands in NSIS scripts"
Script Files
![Page 11: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/11.jpg)
Introduction
• If you want to use a double-quote in a string – you can either use $\" to escape the
quote – or quote the string with a different type
of quote such as ` or '.
Script Files
![Page 12: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/12.jpg)
Introduction
• Commands– Commands lines are in the format
'command [parameters]'File "myfile"
• Comments– Lines beginning with ; or # are
comments. – You can put comments after commands. – You can also use C-style comments to
comment one or more lines
Script File Format
![Page 13: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/13.jpg)
Introduction
• Example:; Comment# Comment
/*CommentComment*/
File "myfile" ; Comment
• If you want a parameter to start with ; or # – put it in quotes.
Script File Format
![Page 14: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/14.jpg)
Introduction
• Numbers
– For parameters that are treated as numbers, use• decimal (the number) or • hexadecimal (with 0x prepended to it, i.e.
0x12345AB), or • Octal (numbers beginning with a 0 and no x).
IntCmp 1 0x1 lbl_equal
– Colors should be set in hexadecimal RGB format, • like HTML but without the #.
SetCtlColors $HWND CCCCCC
Script File Format
![Page 15: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/15.jpg)
Introduction
• Variables– Variables start with $. User variables
should be declared.
Var MYVAR
• Plug-ins– To call a plug-in, use 'plugin::command
[parameters]'.
nsExec::Exec "myfile"
Script File Format
![Page 16: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/16.jpg)
Introduction
• Strings– To represent strings that have spaces, use
quotes:MessageBox MB_OK "Hi there!"
– Quotes only have the property of containing a parameter if they begin the parameter. • They can be either
– single quotes, – double quotes, – or the backward single quote.
– You can escape quotes using $\:
Script File Format
![Page 17: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/17.jpg)
Introduction
• Examples:MessageBox MB_OK "I'll be happy" ; this one puts a ' inside a
string
MessageBox MB_OK 'And he said to me "Hi there!"' ; this one puts a " inside a string
MessageBox MB_OK `And he said to me "I'll be happy again!"` ; this one puts both ' and "s inside a string
MessageBox MB_OK "$\"A quote from a wise man$\" said the wise man" ; this one shows escaping of quotes
• It is also possible to put newlines, tabs etc. in a string using $\r, $\n, $\t etc.
Script File Format
![Page 18: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/18.jpg)
Introduction
• Long commands– To extend a command over multiple lines,
• use a backslash (\) at the end of the line. • For example:
CreateShortCut "$SMPROGRAMS\NSIS\ZIP2EXE project workspace.lnk" \
"$INSTDIR\source\zip2exe\zip2exe.dsw"
MessageBox MB_YESNO|MB_ICONQUESTION \ "Do you want to remove all files in the folder? \ (If you have anything you created that you want \ to keep, click No)" \ IDNO NoRemoveLabel
Script File Format
![Page 19: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/19.jpg)
Introduction
• The default extension for a script file is .nsi
• Header files have the .nsh extension– Header files are useful in case of
• reuseability of the functions• to split one huge script file into smaller pieces
– Headers files can be included by using the follwing command:
• !include <name>.nsh
Script Files
![Page 20: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/20.jpg)
Scripting Structure
General Overview
;Defines!define PRODUCT_NAME "ocs - Outlook Collaboration Sync"!define PRODUCT_VERSION "1.0"!define PRODUCT_PUBLISHER "mausz.net“
;Includes!include "MUI.nsh„;Pages!insertmacro MUI_PAGE_DIRECTORYPage custom DatabaseConfig
;Defintions of Installer AttributesOutFile "ocsSetup.exe"InstallDir "$PROGRAMFILES\ocs"InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""ShowInstDetails show
;Definition of variablesVAR /global typeVAR /global databaseserver
NSIS Script
![Page 21: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/21.jpg)
Scripting Structure
General Overview
…;FunctionsFunction .onInit !insertmacro MUI_INSTALLOPTIONS_EXTRACT_AS \
"databaseconfig.ini" "DatabaseConfig" !insertmacro MUI_INSTALLOPTIONS_EXTRACT_AS \
"licenceconfig.ini" "LicenceConfig"FunctionEnd
;SectionsSection "Application" SEC01 SetOutPath "$INSTDIR" SetOverwrite ifnewer File "syncApp.exe" CreateDirectory \
"$SMPROGRAMS\ocs - Outlook Collaboration Sync" File "App.ico"SectionEnd
NSIS Script
![Page 22: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/22.jpg)
Scripting Structure
• Determine the behavior and the look and feel of the installer.
• With these attributes you can – change texts that will be shown during the installation, – the number of installation types etc.
• Most of these commands can only be set and are not changeable during runtime.– Other basic instructions are Name and InstallDir.
Name „OCS v.1.0"OutFile „syncApp.exe"InstallDir "$PROGRAMFILES\ocs"
Installer Attributes
![Page 23: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/23.jpg)
Scripting Structure
• You can declare your own variables ($VARNAME) with the Var command.
• Variables are global and can be used in any Section or Function.
• Declaring and using a user variable:Var TEST ;Declare the variable
Section testsec StrCpy $TEST "123" ;Now you can use the variable $BLA
SectionEnd
Variables
![Page 24: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/24.jpg)
Scripting Structure
• In addition there is a Stack, which can also be used for temporary storage.
• To access the stack use the commands: – Push adds a value to the stack, – Pop removes one and sets the variable.
• For shared code, there are 20 registers (like $0 and $R0). – These static variables don't have to be
declared and you won't get any name conflicts.
Variables
![Page 25: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/25.jpg)
Scripting Structure
• If you want to use these variables in shared code, – store the original values on the stack – and restore the original values afterwards.
• After calling the function, – the variables contain the same value as before. – Note the order when using multiple variables (last-in first-out):
Function testfunc Push $R0 Push $R1
...code...
Pop $R1 Pop $R0FunctionEnd
Variables
![Page 26: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/26.jpg)
Scripting Structure
• An non-silent installer has a set of wizard pages to let the user configure the installer.
• You can set which pages to display using the Page command (or PageEx for more advanced settings):
Example:Page licensePage componentsPage directoryPage instfilesUninstPage instfiles
Pages
![Page 27: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/27.jpg)
Scripting Structure
• In a common installer there are several things the user can install.– (e.g.: Application, Database, Additional
Features, etc.)
Sections
![Page 28: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/28.jpg)
Scripting Structure
• For each component operations must be implemented.
• In the script, that code is in sections
• Each visible section is a component for the user to choose from.
• Uninstallers can also have multiple sections.– are prefixed with 'un.'.
Sections
![Page 29: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/29.jpg)
Scripting Structure
• Example:Section "Application" SEC01 SetOutPath "$INSTDIR" SetOverwrite ifnewer File "syncApp.exe" CreateShortCut "$SMPROGRAMS\ocs\ocs.lnk“ "$INSTDIR\syncApp.exe" CreateShortCut "$DESKTOP\ocs.lnk“ \
"$INSTDIR\syncApp.exe" File "App.ico" CreateDirectory "xsl" SetOutPath "$INSTDIR\xsl" File "xsl\ACrmToExchange.xsl"SectionEnd
Section "Database" SEC02...
ExecWait '"$R1\Binn\osql.exe" -E -s \ "$R2" -i "$INSTDIR\db\restoreDatabase.sql" -o "$R0" -b'
... ClearErrorsSectionEnd
Section "Configuration" SEC03 SetOutPath "$APPDATA" CreateDirectory "ocs" SetOutPath "$APPDATA\ocs" File "config\licence.xml"SectionEnd
Sections
![Page 30: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/30.jpg)
Scripting Structure
• Functions can contain script code, just like sections.
• The difference between sections and functions is the way they are called.
• There are two types of functions.– user functions and – callback functions.
Functions
![Page 31: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/31.jpg)
Scripting Structure
• User Functions– Are called by the user from – within sections or – other functions using the Call
instruction.
• User functions will not execute unless you call them.
Functions - User
![Page 32: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/32.jpg)
Scripting Structure
• Callback Functions– Are called by the installer upon certain defined
events such as when the installer starts.
• Callbacks are optional.
• Example:– If for example you want to welcome the user to
your installer you will define a function called .onInit. The NSIS compiler will recognize this function as a callback function by the name and will call it when the installer starts.
Functions - Callback
![Page 33: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/33.jpg)
Scripting Structure
• Example:Function .onInit MessageBox MB_YESNO "This will install My Program. Do you wish to continue?" IDYES gogogo
Abort gogogo:FunctionEnd
• Abort has a special meaning in callback functions. – Abort tells the installer to stop initializing the
installer and quit immediately
Functions - Callback
![Page 34: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/34.jpg)
Scripting Structure
• Compiler commands will be executed on compile time on your computer.
• They can be used for conditional compilation, to – include header files, – to execute applications, – to change the working directory and more.
• The most common usage is defines. • Defines are compile time constants.
– You can define your product's version number and use it in your script.
Compiler Commands
![Page 35: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/35.jpg)
Scripting Structure
• Example:!define VERSION "1.0.3"
Name "My Program ${VERSION}"
OutFile "My Program Installer - ${VERSION}.exe“
Compiler Commands
![Page 36: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/36.jpg)
Scripting Structure
• Another common use is macros.– are used to insert code on compile time, – depending on defines – and using the values of the defines.
• The macro's commands are inserts at compile time.
• This allows you to write a general code only once and use it a lot of times but with a few changes.
Compiler Commands - Macros
![Page 37: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/37.jpg)
Scripting Structure
• Example:!macro MyFunc UNFunction ${UN}MyFunc Call ${UN}DoRegStuff ReadRegStr $0 HKLM Software\MyProgram key DetailPrint $0FunctionEnd!macroend
!insertmacro MyFunc ""!insertmacro MyFunc "un.“
• This macro helps you avoid writing the same code for both the installer and the uninstaller.
• The two !insertmacros insert two functions, one for the installer called MyFunc and one for the uninstaller called un.MyFunc and both do exactly the same thing.
Compiler Commands - Macros
![Page 38: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/38.jpg)
Debugging Scripts
• There are a few possibilities to help you debugging the code. – To display the contents of variables you
should use • MessageBoxes or • DetailPrint.
– To get a brief overview about all variables you should use the plug-in DumpState.
![Page 39: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/39.jpg)
Debugging Scripts
• By default all actions of the Installer are printed out in the Log Window. – You can access the log if you right-click
in the Log Window and select "Copy Details To Clipboard".
• Write everything into a file
![Page 40: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/40.jpg)
NSIS Framework
• Utilities– MakeNSISW (compiler interface)– Zip2Exe (convert ZIP to SFX)– Language Files
• Documentation– NSIS User Manual– FAQ– NSIS Wiki
![Page 41: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/41.jpg)
Utilities
• NSIS Installers are generated with MakeNSISW
• How?
– Simply right click on a .nsi file and selecting compile
– Commandlineusage:
makensis [option | script.nsi | - [...]]
MakeNSISW
![Page 42: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/42.jpg)
Utilities
• Zip2Exe is able to convert a zip File into a simple installer
• Customizations can be done by changing the header files (Contrib\zip2exe folder)
Zip2Exe
![Page 43: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/43.jpg)
Utitities
• After pressing generate, the installer script will be compiled and is ready for use!
Zip2Exe
![Page 44: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/44.jpg)
Utilities
• NSIS supports multiple languages
• 49 Language Packs come out of the box (contrib\language folder)
_
![Page 45: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/45.jpg)
Documentation
• Includes:– Introduction to NSIS
– Tutorial: The Basis
– Reference book
• Comes out of the box
NSIS User Manual
![Page 46: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/46.jpg)
Documentation
• Answers on the most common questions on NSIS can be found here
FAQ
http://nsis.sourceforge.net/wiki/Category:FAQ
![Page 47: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/47.jpg)
Documentation
• NSIS Community Portal – NSIS WIKI– Sharing of
• Examples• Plug-Ins• Tutorials• Knowledge around
NSIS• Etc.
Wiki
http://nsis.sourceforge.net/wiki
![Page 48: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/48.jpg)
Development Tools
• HM NIS– http://hmne.sourceforge.net/
• Venis VIX– http://www.spaceblue.com/venis/
• EclipsePlugin– http://eclipsensis.sourceforge.net/
![Page 49: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/49.jpg)
Development Tools
• Multiple scripts edition and compilation interface (MDI).
• Translatable interface to any language – (available in English, Spanish,
Polish, French, Czech, Italian, Russian, Greek, German, Chinese, Ukrainian, Portuguese (Brazil), Korean).
• Syntax highlighting with customizable colors and text attributes.
• InstallOptions Designer.
• Plugins support.
HM NIS - Functionality
![Page 50: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/50.jpg)
Development Tools
• Wizard (special for beginner) – that will guide for all steps to create a standard Windows
Setup program.
• Script creation from template files.
• Code templates with most common commands.
• Basic NSIS command help with only move the mouse cursor over a command in the editor.
• Advanced NSIS command help pressing F1 key.
• Execution of the generate Setup program after script compilation (to try the setup program).
• No need bulky OCX or run time libraries.
HM NIS - Functionality
![Page 51: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/51.jpg)
Installer Example
• Requirements for the installer– Ordinary file copy– Creation of links– Creation of a config file (xml)
• using an external shell programm
– Creation of check procedures• is .NET framework installed?
![Page 52: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/52.jpg)
Installer Example
• Approach– Creating a simple installer using the
wizard of HM NIS
– Including a batch job• Creation of a XML Config File
– Including check function (registry based)• Is .Net Framework available
Approach
![Page 53: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/53.jpg)
Installer Example
• Start HM NIS EDIT and press– File -> New script from Wizard…
HM NIS - Wizard
![Page 54: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/54.jpg)
Installer Example
• Fill in information about your installation– It is used during the installation process
HM NIS - Wizard
![Page 55: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/55.jpg)
Installer Example
• General installer optiones– Setup Icon– Setup File– Setup Language
• Multiple languages possible
– GUI Type• Modern• Classic• None
– Compression
HM NIS - Wizard
![Page 56: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/56.jpg)
Installer Example
• General installer optiones– Application default
directory
– Licence File• Is shown as before the
installer starts
HM NIS - Wizard
![Page 57: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/57.jpg)
Installer Example
• Application Files– The installer can
contain different chooseable Installationsections
– This can be setup in the top-left field (etc. Application)
– Additional the following checkbox must be activated
• Allow user to select the componenets to install
HM NIS - Wizard
![Page 58: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/58.jpg)
Installer Example
• Shortcut settings– Application Start Menu
folder name
– Allow user to change the Start Menu folder name
– Create an Internet shortcut in the Start Menu folder
– Create an Uninstall icon in the Start Menu folder
– Additional shortcuts can be added via the listbox on the bottom
HM NIS - Wizard
![Page 59: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/59.jpg)
Installer Example
• Post-Installation settings
– Executeable program file
– Parameter
– Readme - File
HM NIS - Wizard
![Page 60: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/60.jpg)
Installer Example
• Uninstaller Settings
– Uninstall prompt
– Uninstall success message
– Uninstall Icon
HM NIS - Wizard
![Page 61: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/61.jpg)
Installer Example
• Last Wizardpage
HM NIS - Wizard
![Page 62: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/62.jpg)
Installer Example
• The simple installer is ready for testing!• Press Shift+F9 for compile and run
HM NIS - Wizard
![Page 63: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/63.jpg)
Installer Example
HM NIS - Wizard
![Page 64: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/64.jpg)
Installer Example
• What was created in behind?– The entire installer script <installername>.nsi
– Executeable Setup File
HM NSI Wizard - Background
![Page 65: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/65.jpg)
Installer Example
HM NSI Wizard - Script
Definitions!define PRODUCT_NAME "ocs - Outlook Collaboration Sync"!define PRODUCT_VERSION "1.0"!define PRODUCT_PUBLISHER "mausz.net"!define PRODUCT_WEB_SITE "http://www.mausz.net"!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\syncApp.exe"!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"!define PRODUCT_UNINST_ROOT_KEY "HKLM„…
Pages; Welcome page!insertmacro MUI_PAGE_WELCOME; License page!insertmacro MUI_PAGE_LICENSE "..\..\sync\installer\lizenz.rtf"; Components page!insertmacro MUI_PAGE_COMPONENTS; Directory page!insertmacro MUI_PAGE_DIRECTORY; Instfiles page!insertmacro MUI_PAGE_INSTFILES; Finish page!define MUI_FINISHPAGE_RUN "$INSTDIR\config\XmlConfigWriter.exe"!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\config\.svn\README.txt"!insertmacro MUI_PAGE_FINISH…
![Page 66: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/66.jpg)
Installer Example
HM NSI Wizard - Script
Languages; Language files!insertmacro MUI_LANGUAGE "English"
Additional Installer AttributesName "${PRODUCT_NAME} ${PRODUCT_VERSION}"OutFile "Setup.exe"InstallDir "$PROGRAMFILES\ocs - Outlook Collaboration Sync"InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""ShowInstDetails showShowUnInstDetails show
Installer SectionsSection "Application" SEC01 SetOutPath "$INSTDIR" SetOverwrite try File "App.ico“…SectionEnd
Section -Post WriteUninstaller "$INSTDIR\uninst.exe" WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\config\XmlConfigWriter.exe„…SectionEnd
![Page 67: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/67.jpg)
Installer Example
HM NSI Wizard - Script
Uninstaller FunctionsFunction un.onUninstSuccess HideWindow MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."FunctionEnd
Function un.onInit MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2 AbortFunctionEnd
Uninstaller Section
Section Uninstall Delete "$INSTDIR\${PRODUCT_NAME}.url" Delete "$INSTDIR\uninst.exe" Delete "$INSTDIR\xsl\CExchangeToCrm.xsl“ RMDir "$INSTDIR\config\.svn" RMDir "$INSTDIR\config" RMDir "$INSTDIR" .. DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}" SetAutoClose trueSectionEnd
![Page 68: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/68.jpg)
Installer Example
!define PRODUCT_NAME "ocs - Outlook Collaboration Sync"
!define PRODUCT_VERSION "1.0"
• These constants can be used within the entire script
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
Defintions
![Page 69: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/69.jpg)
Installer Example
• The used Pages are predefined pages which are part of the NSIS2 Framework; Welcome page!insertmacro MUI_PAGE_WELCOME; License page!insertmacro MUI_PAGE_LICENSE "..\..\sync\installer\lizenz.rtf"; Components page!insertmacro MUI_PAGE_COMPONENTS…
• Predefined are called with!insertmacro pagename [parameters]
• The order of the entries decides about the point of execution
Pages
![Page 70: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/70.jpg)
Installer Example
• Custompages are called withPage custom pagename [Parameters]
• Example:
Page custom DatabaseConfig
Page custom LicenceConfig
Pages
![Page 71: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/71.jpg)
Installer Example
• Languagepacks can be included with!insertmacro MUI_LANGUAGE “Language"
• Available languages are listed in the following folder:
NSIS Folder\Contrib\Language files
Languages
![Page 72: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/72.jpg)
Installer Example
• ApplicationnameName "${PRODUCT_NAME} ${PRODUCT_VERSION}"
• Output File (Installer)OutFile "Setup.exe„
• Installation DirectoryInstallDir "$PROGRAMFILES\ocs„
• Registry KeyInstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" "„
• Hide or show the progress during installationShowInstDetails showShowUnInstDetails show
Installer Attributes
![Page 73: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/73.jpg)
Installer Example
• As defined = „Application“Section "Application" SEC01
• Definition of the OutputPath SetOutPath "$INSTDIR"
• SetOverwrite try defines to overwrite existing files if possible SetOverwrite try
• The File commando copies the given File into the defined Output Path
File "App.ico"
• Creation of a directory CreateDirectory "$SMPROGRAMS\ocs"
• Creation of a short cut CreateShortCut "$SMPROGRAMS\ocs\ocs.lnk„ \ "$INSTDIR\syncApp.exe"
SectionEnd
Installer Section
![Page 74: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/74.jpg)
Installer Example
• „Eventdriven“ functions• Is called in case of a successful uninstallation
Function un.onUninstSuccess HideWindow MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was
successfully removed from your computer."FunctionEnd
• Is called in case of starting the uninstallation process
Function un.onInit MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you
sure you want to completely remove $(^Name) and all of its components?" IDYES +2
AbortFunctionEnd
Uninstaller Functions
![Page 75: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/75.jpg)
Installer Example
• Uninstaller SectionSection Uninstall
– Deletes the given fileDelete "$INSTDIR\xsl\CExchangeToCrm.xsl“
– Deletes the given directory RMDir "$INSTDIR\xsl"
– Deletes the given registry key DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
SectionEnd
Uninstaller Section
![Page 76: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/76.jpg)
Installer Example
• Approach– Creation of a custom page
• input option for username, • password and • url
– Include to the installer
– Creation of an user function• Call of a batch job according to the given
config input values
Creation of a XML config file
![Page 77: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/77.jpg)
Installer Example
• Using HM NSI a new custom page can be created with
– File -> New Install Options file
Creating the custom page
![Page 78: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/78.jpg)
Installer Example
• A control toolbar can be found on the right side of the HM NSI Window
• A control can be moved to the window by one click on the required control and another click on the desired position within the custom page
Creating the custom page
![Page 79: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/79.jpg)
Installer Example
• On the right side a property bar is located which can be used to configure the controls
• The FieldNum property is very important, because this is used within the script to access the control
• After every control is configured the custom page must be safed (etc. licenceconfig.ini)
Creating the custom page
![Page 80: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/80.jpg)
Installer Example
• First of all the callbackfunction .onInit must be created:
Function .onInit
!insertmacro MUI_INSTALLOPTIONS_EXTRACT_AS "licenceconfig.ini" "LicenceConfig"
FunctionEnd
• The MUI_INSTALLOPTIONS_EXCTRACT_AS Macro is needed to include custompages
Include a custom page into the Script
![Page 81: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/81.jpg)
Installer Example
• The custom page must be placed into the right page order
; Welcome page!insertmacro MUI_PAGE_WELCOME; License page!insertmacro MUI_PAGE_LICENSE "lizenz.rtf"; Components page!insertmacro MUI_PAGE_COMPONENTS; Directory page!insertmacro MUI_PAGE_DIRECTORY
Custom PagesPage custom LicenceConfig; Instfiles page!insertmacro MUI_PAGE_INSTFILES...
Include a custom page into the Script
![Page 82: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/82.jpg)
Installer Example
• A function must be created with the defined custom page name
Function LicenceConfig
!insertmacro MUI_HEADER_TEXT "LicenceConfig" "subtitle"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "LicenceConfig"
!insertmacro MUI_INSTALLOPTIONS_READ $6 "LicenceConfig" "Field 6" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $7 "LicenceConfig" "Field 7" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $8 "LicenceConfig" "Field 8" "State"
Include a custom page into the Script
![Page 83: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/83.jpg)
Installer Example
• Macro description– Header text configuration
!insertmacro MUI_HEADER_TEXT "LicenceConfig" "subtitle“
– Showing the page!insertmacro MUI_INSTALLOPTIONS_DISPLAY "LicenceConfig
– Read a value from a control into a variabel!insertmacro MUI_INSTALLOPTIONS_READ $6 "LicenceConfig" "Field 6" "State“
!insertmacro MUI_INSTALLOPTIONS_READ $7 "LicenceConfig" "Field 7" "State“
!insertmacro MUI_INSTALLOPTIONS_READ $8 "LicenceConfig" "Field 8" "State"
FunctionEnd
Include a custom page into the Script
![Page 84: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/84.jpg)
Installer Example
!insertmacro MUI_HEADER_TEXT "LicenceConfig" "subtitle“
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "LicenceConfig
!insertmacro MUI_INSTALLOPTIONS_READ $6 "LicenceConfig" "Field 6" "State“
!insertmacro MUI_INSTALLOPTIONS_READ $7 "LicenceConfig" "Field 7" "State“
!insertmacro MUI_INSTALLOPTIONS_READ $8 "LicenceConfig" "Field 8" "State"
FunctionEnd
Include a custom page into the Script
Field 6Field 7Field 8
Header_Text
![Page 85: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/85.jpg)
Installer Example
• Save the given values into a xml file– This is done by calling a batch program with the
required parameters
– To call a batch programm the command ExecWait is used
ExecWait '"$INSTDIR\config\XmlConfigWriter.exe" “$6" “$7" "$8"‘
• Now, the installer is ready for use with enhanced functionality
Include a custom page into the Script
![Page 86: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/86.jpg)
Installer Example
• To check if the .Net Framwork is available the following function must be included
Function GetDotNETVersion Push $0 Push $1
System::Call "mscoree::GetCORVersion(w .r0, i ${NSIS_MAX_STRLEN}, *i) i .r1"
StrCmp $1 "error" 0 +2 StrCpy $0 "not found"
Pop $1 Exch $0FunctionEnd
Check procedure
http://nsis.sourceforge.net/wiki/Get_.NET_Version
![Page 87: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/87.jpg)
Installer Example
• This functions is called during the .onInit Function
Function .onInit
Call GetDotNETVersion
Pop $0
StrCmp $0 "not found" finish
Finish:MessageBox MB_OK|MB_ICONSTOP ".NET runtime library is not installed. Please download the runtime envirnoment from http://www.microsoft.com/download and install it!"
Abort
FunctionEnd
Check procedure
http://nsis.sourceforge.net/wiki/Get_.NET_Version
![Page 88: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/88.jpg)
Appendix A
• Generates self contained executable installers
• Support for ZLib, BZip2 and LZMA data compression – files can be compressed individually or together)
• Uninstall support – installer can generate an uninstaller)
• Customizable user interface – dialogs, fonts, backgrounds, icons, text, checkmarks,
images etc.
• Classic and Modern wizard interface[http://nsis.sourceforge.net/features/]
Features
![Page 89: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/89.jpg)
Appendix A
• Fully multilingual, support for multiple languages (including RTL languages) in one installer. – More than 40 translations are already available, but you can
also create your own.
• Page system: – You can add standard wizard pages or custom pages
• User selection of installation components, tree for component selection
• Multiple install configurations – (usually Minimal, Typical, Full), – and custom configuration
[http://nsis.sourceforge.net/features/]
Features
![Page 90: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/90.jpg)
Appendix A
• Installer self-verification using a CRC32 checksum
• Small overhead over compressed data size – (34 KB with default options)
• Ability to display a license agreement in text or RTF format
• Ability to detect destination directory from the registry
[http://nsis.sourceforge.net/features/]
Features
![Page 91: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/91.jpg)
Appendix A
• Easy to use plug-in system – (lots of plug-ins for creation of custom dialogs, internet
connections, HTTP downloading, file patching, Win32 API calls etc. are included)
• Installers can be as large as 2GB• Optional silent mode for automated installations• A preprocessor with support for defined symbols,
macro's, conditional compilation, standard predefines
• A lovely coding experience with elements of PHP and assembly – (includes user variables, a stack, real flow control, etc.)
[http://nsis.sourceforge.net/features/]
Features
![Page 92: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/92.jpg)
Appendix A
• Installers have their own VMs that let you write code that can support:– File extraction (with configurable overwrite
parameters) – File/directory copying, renaming, deletion,
searching – Plug-in DLL calling – DLL/ActiveX control registration/deregistration – Executable execution (shell execute and wait
options) – Shortcut creation
[http://nsis.sourceforge.net/features/]
Features
![Page 93: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/93.jpg)
Appendix A
– Registry key reading/setting/enumerating/deleting
– INI file reading/writing – Generic text file reading/writing – Powerful string and integer manipulation – Window finding based on class name or title – User interface manipulation (font/text setting) – Window message sending – User interaction with message boxes or custom
pages
[http://nsis.sourceforge.net/features/]
Features
![Page 94: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/94.jpg)
Appendix A
– Branching, comparisons, etc. – Error checking – Reboot support, including delete or
rename on reboot – Installer behaviour commands (such as
show/hide/wait/etc) – User functions in script – Callback functions for user actions
[http://nsis.sourceforge.net/features/]
Features
![Page 95: NSIS Tutorial](https://reader035.vdocument.in/reader035/viewer/2022081417/55cf9bcd550346d033a76df2/html5/thumbnails/95.jpg)
Appendix A
• Completely free for any use.
[http://nsis.sourceforge.net/features/]
Features