Installing with NSIS

Photo by Patrick Lindenberg on Unsplash

What is an installer?

What is the difference?

Which install framework to use?

Installer example

Creating a basic installer

code basic.nsi

Variables

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

UI and basic info

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

!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

  • 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 ".\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

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

--

--

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