Introduction

NSIS 2 makes it is possible to create installers with a custom user interface.

I made this interface with a modern wizard style, like the wizards of recent Windows versions. This new interface also features new graphics and a description area on the component selection page.

To use this new interface for your installer, you need to add some code to your NSIS script. Read this document for more info!

Screenshots

How to use

The Modern UI has a macro system, so most of the code has already been written for you!

The easiest way to use the Modern UI is to customize one of the example scripts, but you can also modify an existing script.

Note: If you want to add a double quote (") to a Modern UI string, you should always escape it ($\"), because the Modern UI macro's use " to separate parameters.

To use the Modern UI in an existing script, you should follow these steps:

1. Include the header file

!include "${NSISDIR}\Contrib\Modern UI\System.nsh"

2. Define the name and version of your software

!define MUI_PRODUCT "Test Software" ;Define your own software name here
!define MUI_VERSION "1.0" ;Define your own software version here

3. Define settings

Use defines to let the Modern UI know what it should insert. Most defines (i.e. MUI_WELCOMEPAGE) don't need a value, but others should be used to define a value for the Modern UI (i.e. MUI_FINISHPAGE_RUN):

!define MUI_WELCOMEPAGE
!define MUI_FINISHPAGE_RUN "$INSTDIR\Application.exe"

All defines are optional, if you don't define a page, the page won't be shown. If you don't define a value, the Modern UI won't use that option.

MUI_WELCOMEPAGE
Show the welcome page.

MUI_LICENSEPAGE
Show the license page.

MUI_COMPONENTSPAGE
Show the component selection page.

MUI_DIRECTORYPAGE
Show the directory selection page.

MUI_STARTMENUPAGE
Show the Start Menu Folder selection page.

MUI_STARTMENU_VARIABLE
Variable to store the current Start Menu Folder. Default is $9. You cannot use this variable in your script (or you should Push/Pop it).e.

MUI_STARTMENU_DEFAULTFOLDER
The default Start Menu Folder. Use $(LANGSTRINGNAME) as value is you want to use a language string.

MUI_FINISHPAGE
Show the Finish page.

MUI_FINISHPAGE_RUN
Application which the user can select to run (using a checkbox). You don't need to put quotes around the filename when it contains spaces.

MUI_FINISHPAGE_RUN_PARAMETERS
Parameters for the application to run. Don't forget to escape double quotes ($\") in the value.

MUI_FINISHPAGE_RUN_NOTCHECKED
Do not check the 'Run program' checkbox by default

MUI_FINISHPAGE_SHOWREADME
File which the user can select to view (using a checkbox). You don't need to put quotes around the filename when it contains spaces. Use $(LANGSTRINGNAME) as value is you want to use a language string.

MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
Do not check the 'Show Readme' checkbox by default

MUI_FINISHPAGE_NOAUTOCLOSE
Do not automatically jump to the finish page, to allow the user to check the log.

MUI_FINISHPAGE_NOREBOOTSUPPORT
Disables support for a reboot option. Use this to save some space if you are not using /REBOOTOK or SetRebootFlag.

MUI_ABORTWARNING
Show a message box with a warning (are you sure?) when the user closes the installation.

MUI_CUSTOMPAGECOMMANDS
Don't insert Page commands. Use this if you are using custom Page commands to add your own pages.

MUI_CUSTOMGUIINIT
Don't insert the .onGUIInit function. Use this if you want to add custom code to the function. More info...

MUI_UNINSTALLER
Define if you are using an uninstaller.

MUI_UNCONFIRMPAGE
Show the uninstall confirm page.

MUI_UNCUSTOMPAGECOMMANDS
Don't insert UninstPage commands. Use this if you are using custom UninstPage commands to add your own pages.

MUI_UNCUSTOMGUIINIT
Don't insert the un.onGUIInit function. Use this if you want to add custom code to the function. More info...

4. Insert custom pages (optional)

If you want to use custom pages (define MUI_CUSTOMPAGECOMMANDS or MUI_UNCUSTOMPAGECOMMANDS!), you should insert them now.

More info...

5. Insert language files

Insert the Modern UI language files for the languages you are using:

!insertmacro MUI_LANGUAGE "English"

The Modern UI language files load the NLF language files, so you should not use LoadLanguageFile.

You don't need to edit the language files if you want to customize some strings. Use defines before you insert the language file:

!define MUI_BRANDINGTEXT "French Branding Text"
!insertmacro MUI_LANGUAGE "French"

Have a look at the language files for a complete list of all the string names.

Note: Not all language files contain strings for the new Start Menu Folder selection-, Welcome- and Finish page yet. If you are using one of these pages and the language file does not contain these strings, you should always define them.
Please help to translate the new strings and post them at the NSIS Forum.

6. Define interface settings (optional)

You can also change the settings of the interface by using defines:

!define MUI_UI "${NSISDIR}\Contrib\UIs\modern2.exe"

If you don't define a setting, the default will be used.

The following settings are available: (default values)

MUI_UI (${NSISDIR}\Contrib\UIs\modern.exe)
The interface file with the dialog resources.

MUI_ICON (${NSISDIR}\Contrib\Icons\modern-install.ico)
The icon of the instaleller.

MUI_UNICON (${NSISDIR}\Contrib\Icons\modern-uninstall.ico)
The icon of the uninstaleller.

MUI_CHECKBITMAP (${NSISDIR}\Contrib\Icons\modern.bmp)
The bitmap with images for the checks of the component select treeview.

MUI_FONT, MUI_FONTSIZE (MS Shell Dlg, 8)
The font for the normal texts.

MUI_FONT_HEADER, MUI_FONTSIZE_HEADER, MUI_FONTSTYLE_HEADER (MS Sans Serif, 8, 700)
The font for the title in the header. Fontstyle: [weight] [/ITALIC] [/UNDERLINE] [/STRIKE]

MUI_FONT_TITLE, MUI_FONTSIZE_TITLE, MUI_FONTSTYLE_TITLE (Verdana, 12, 700)
The font for the title on the Welcome and Finish page. Fontstyle: [weight] [/ITALIC] [/UNDERLINE] [/STRIKE]

MUI_INSTALLCOLORS (/windows)
The colors of the details screen, hexadecimal ("foreground" "background").

MUI_PROGRESSBAR (smooth)
The style of the progress bar ("colored" to use the MUI_INSTALLCOLORS or "" for a old-school windows look).

MUI_SPECIALINI (${NSISDIR}\Contrib\Modern UI\ioSpecial.ini)
Install Options INI File for the Welcome and Finish page.

MUI_SPECIALBITMAP (${NSISDIR}\Contrib\Icons\modern-wizard.bmp)
Bitmap for the Welcome and Finish page.

MUI_BGCOLOR (0xFFFFFF)
Background color for the header, Welcome page and Finish page.

7. Insert the MUI_SYSTEM macro

!insertmacro MUI_SYSTEM

8. Insert the MUI_SECTIONS_FINISHHEADER macro

If you are not using a Finish page without defining MUI_FINISHPAGE_NOAUTOCLOSEWINDOW and have not set AutoCloseWindow to true, you should insert the MUI_SECTIONS_FINISHHEADER after all the sections to display the finish header:

!insertmacro MUI_SECTIONS_FINISHHEADER

For the uninstaller, insert MUI_UNFINISHHEADER at the end of the Uninstaller section:

!insertmacro MUI_UNFINISHHEADER

9. Set the descriptions for the sections

Insert the description macro's to set the descriptions for the sections. These descriptions will be displayed on the component selection page, when the users hovers the mouse over a section. If you don't want to use descriptions, use the modern3.exe UI.

LangString DESC_Section1 ${LANG_ENGLISH} "Description of section 1."
LangString DESC_Section2 ${LANG_ENGLISH} "Description of section 2."

!insertmacro MUI_FUNCTIONS_DESCRIPTION_BEGIN
  !insertmacro MUI_DESCRIPTION_TEXT ${Section1} $(DESC_Section1)
  !insertmacro MUI_DESCRIPTION_TEXT ${Section2} $(DESC_Section2)
!insertmacro MUI_FUNCTIONS_DESCRIPTION_END

Add an extra parameter to the Section command to set the define with the section number:

Section "Section Name 1" Section1
  ...
SectionEnd

10. Reserve Files

If you are using BZIP2 compression, you might need to insert ReserveFile commands. More info...

Custom pages

Custom page commands

If you want add custom pages to your installer, you should insert your own page commands to set the order of the pages and the names of the page functions:

LangString TEXT_IO_WINDOWTITLE ": Install Options Page Title"

!insertmacro MUI_PAGECOMMAND_WELCOME
!insertmacro MUI_PAGECOMMAND_LICENSE
!insertmacro MUI_PAGECOMMAND_COMPONENTS
!insertmacro MUI_PAGECOMMAND_DIRECTORY
Page custom FunctionName $(TEXT_IO_WINDOWTITLE) ;A custom page
!insertmacro MUI_PAGECOMMAND_INSTFILES
!insertmacro MUI_PAGECOMMAND_FINISH

This is also possible in the uninstaller:

LangString un.UNTEXT_IO_WINDOWTITLE ": Install Options Page Title"

!insertmacro MUI_UNPAGECOMMAND_CONFIRM
UninstPage custom un.FunctionName $(UNTEXT_IO_WINDOWTITLE) ;A custom page
!insertmacro MUI_UNPAGECOMMAND_INSTFILES

Don't forget to define MUI_CUSTOMPAGECOMMANDS or MUI_UNCUSTOMPAGECOMMANDS and to insert the Page commands before on the right position.

Call Install Options

Have a look at the Install Options documentation for info about creating Install Options INI Files.

First, you need to extract your InstallOptions INI File in the .onInit function (un.onInit for the uninstaller):

Function .onInit
  !insertmacro MUI_INSTALLOPTIONS_EXTRACT "ioFile.ini"
FunctionEnd

You can call Install Options in the function defined with the Page or UninstPage command:

LangString TEXT_IO_TITLE ${LANG_ENGLISH} "Install Options Page Title"
LangString TEXT_IO_SUBTITLE ${LANG_ENGLISH} "A subtitle"

Function FunctionName
  !insertmacro MUI_HEADER_TEXT "$(TEXT_IO_TITLE)" "$(TEXT_IO_SUBTITLE)"
  !insertmacro MUI_INSTALLOPTIONS_DISPLAY "ioFile.ini"
FunctionEnd

For custom fonts and colors, macro's for the initDialog and show functions of InstallOptions are also available:

LangString TEXT_IO_TITLE ${LANG_ENGLISH} "Install Options Page Title"
LangString TEXT_IO_SUBTITLE ${LANG_ENGLISH} "A subtitle"

Function FunctionName ;FunctionName defined with Page command

  !insertmacro MUI_HEADER_TEXT "$(TEXT_IO_TITLE)" "$(TEXT_IO_SUBTITLE)"

  Push $R0
  Push $R1
  Push $R2

    !insertmacro MUI_INSTALLOPTIONS_INITDIALOG "ioFile.ini"
    Pop $R0
    
    GetDlgItem $R1 $R0 1200 ;1200 + Field number - 1
    
    ;$R1 contains the HWND of the first field
    CreateFont $R2 "Tahoma" 10 700 
    SendMessage $R1 ${WM_SETFONT} $R2 0
	
    !insertmacro MUI_INSTALLOPTIONS_SHOW
	
  Pop $R1
  Pop $R1
  Pop $R0

FunctionEnd

To read or write values to the INI Files on runtime, use these macro's:

!insertmacro MUI_INSTALLOPTIONS_READ $VAR "ioFile.ini" "Field #" "Value Name"
!insertmacro MUI_INSTALLOPTIONS_WRITE "ioFile.ini" "Field #" "Value Name" "Value"

Reserve files

If you are using BZIP2 compression, it's important that files which are being extracted in the .onInit function or in Page functions are first in the data block, because this will make your installer start faster.

If these functions are not above any other File command, insert the ReserveFile commands or macro's above other File commands:

ReserveFile "ioFile.ini" ;Your own InstallOptions INI files

!insertmacro MUI_RESERVEFILE_WELCOMEFINISHPAGE ;Welcome- or Finish page
!insertmacro MUI_RESERVEFILE_INSTALLOPTION ;InstallOptions
!insertmacro MUI_RESERVEFILE_LANGDLL ;LangDLL (language selection page)

Examples

Basic: Basic.nsi
Multilanguage: MultiLanguage.nsi
Custom pages: InstallOptions.nsi
Start Menu Folder selection: StartMenu.nsi
Welcome/Finish page: WelcomeFinish.nsi

The interface

Different versions

There are three different versions of the Modern UI. Modern.exe contains the dialogs of the standard interface. If you have an installer with a lot of subsections or long section names, use modern2.exe, which has a different component selection page. Use modern3.exe if you are not using descriptions.

Customize the dialogs

To change elements on the dialogs, modify modern?.exe in the Contrib\UIs directory using a resource editor such as Resource Hacker.

The 'Please wait while Setup is loading...' text on the splash screen which is being displayed when the installer is starting (Verifying installer, Unpacking data) cannot be changed by the script, because the installer is not started yet when this dialog is being displayed. If you want to change this text, modify dialog 111 of modern?.exe.
The 'Verifying installer' and 'Unpacking data' texts are defined in the language header file of the NSIS exehead (Source\exehead\lang.h). To change them, you need to edit this file and recompile NSIS.

To modify the Welcome and Finish dialog, edit the Install Options INI File ioWizard.ini in the 'Contrib\Modern UI' directory.

Customize the GUIInit function

If you want to insert your own code in the .onGUIInit function, define MUI_CUSTOMGUIINIT (MUI_UNCUSTOMGUIINIT for the uninstaller) on the right position and insert the MUI_GUIINIT (MUI_UNGUIINIT for the uninstaller) macro in your .onGUIInit or un.onGUInit function:

!define MUI_CUSTOMGUIINIT

Function .onGUIInit
  !insertmacro MUI_GUIINIT
  ...your own code...
FunctionEnd

Version history

  • 1.62 - December 15, 2002
    • No problems anymore when using both 'Run program' and 'Show Readme' on the finish page
    • Default state of checkboxes on the finish page can be changed
    • Welcome / Finish page compatible with custom DPI settings
    • Converted Install Options INI files to use dialog units
    • Support for multilingual branding texts
    • More ReserveFile macro's
    • Background color can be changed with a define

  • 1.61 - December 5, 2002
    • Final version for NSIS 2 beta 0
    • modern3.exe UI without description area
    • Added define to show uninstall confirm page
    • Added language string for finish page title and continue to uninstall
    • Define for parameters for the application to run on the finish page
    • Bugfixes

  • 1.6 - November 18, 2002
    • Welcome / Finish page
    • Automatic ask for reboot on the finish page
    • Create no shortcut option on the Start Menu Folder selection page
    • Customizing GUIInit functions easier
    • Minor font / UI changes

Complete version history

Credits

Made by Joost Verburg.
Icons designed by Nikos Adamamas, aka adni18.
Thanks to Amir Szekely, aka KiCHiK, for his work on NSIS to make this possible.

Help

Please post questions at the NSIS Forum.

License

Copyright © 2002 Joost Verburg

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute
it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; 
   you must not claim that you wrote the original software.
   If you use this software in a product, an acknowledgment in the
   product documentation would be appreciated but is not required.
2. Altered versions must be plainly marked as such,
   and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any distribution.