Sign in

We want that our newly created program is easily delivered to the client and is easy to install. We need to provide an installer.

Photo by Patrick Lindenberg on Unsplash

What is an installer?

The Oxford Dictionary tells us the following “A piece of software that installs a program on a computer’s hard disk”.

What is the difference?

An installer has extra options and takes care of the integration in the OS.

Which install framework to use?

There are many install frameworks on the market, some open source and some proprietary. The most commonly know installers are Windows Installer, InstallShield and NSIS (Nullsoft scriptable install system). We are going to use NSIS, simply because it is relatively easy to use and open source.

Installer example

Creating a basic installer

NSIS is a scriptable installer, so we need to create a script file. NSIS uses the .nsi file extension.

code basic.nsi

Variables

To declare variables we need to do the following.

!define <VARIABLE_NAME> <”VALUE”>
!define PRODUCT_NAME "SimpleServe"
!define PRODUCT_VERSION "1.0"
!define PUBLISHER "Covert Barnacle Developments"

UI and basic info

Now you need to use the previous variables to fill in some basic program information like the name, installer name and branding text.

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "${PRODUCT_NAME}-installer.exe"
BrandingText "${PUBLISHER}"
Unicode True
SetCompressor lzma
InstallDir "$PROGRAMFILES64\${PRODUCT_NAME}"
InstallDirRegKey HKCU "Software\${PRODUCT_NAME}" ""
RequestExecutionLevel admin

Interface

The installer has of course a user interface to interact with. NSIS has a few years ago released a new installer interface called modern UI 2. We need to include the configuration for this interface in the installer.

!include "MUI2.nsh"
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"

Installation sections

We will now see the most important part of the installer, the sections. Sections are viewed as component in the componet page of the installer. We can also make section groups to create subsections.

  • File → File that needs to be copied to SetOutPath.
  • WriteUninstaller → Creating an uninstaller for the program, more about this later.
Section "Webserver" Sec_Simpleserve
SectionIn RO
WriteRegStr HKCU "Software\${PRODUCT_NAME}" "" $INSTDIR
SetOutPath "$INSTDIR"
File ".\simpleserve.py"
WriteUninstaller $INSTDIR\uninstall.exe
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}.lnk" "python" '"$INSTDIR\simpleserve.py"'
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME} Uninstaller.lnk" "$INSTDIR\uninstall.exe"
SectionEnd
LangString DESC_Sec_Simpleserve ${LANG_ENGLISH} "A test section."!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${Sec_Simpleserve} $(DESC_Sec_Simpleserve)
!insertmacro MUI_FUNCTION_DESCRIPTION_END

Uninstallation sections

To remove the software, we need to create an uninstallation section for the previously mentioned uninstaller.

Section "Un.Webserver" un.Sec_Simpleserve
RMDir /r "$INSTDIR"
Delete "$SMPROGRAMS\${PRODUCT_NAME}.lnk"
Delete "$SMPROGRAMS\${PRODUCT_NAME} Uninstaller.lnk"
RMDir "$INSTDIR"
DeleteRegKey /ifempty HKCU "Software\${PRODUCT_NAME}"
Delete "$INSTDIR\Uninstall.exe"
SectionEnd