Installing with NSIS

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


To declare variables we need to do the following.

!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.

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


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_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.

  • SetOutPath → Place where the program needs to be installed.
  • 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 ".\"
WriteUninstaller $INSTDIR\uninstall.exe
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}.lnk" "python" '"$INSTDIR\"'
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME} Uninstaller.lnk" "$INSTDIR\uninstall.exe"
LangString DESC_Sec_Simpleserve ${LANG_ENGLISH} "A test section."!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${Sec_Simpleserve} $(DESC_Sec_Simpleserve)

Uninstallation sections

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

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



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store