Download and install the NSIS (Nullsoft Scriptable Install System) package
From here.
Run the NSIS installation package using their setup wizard:
Write an NSIS (*.nsi) script file
An .nsi file is just a text file with script code.
Commands are in the format: command [parameters]
Comments are included using ‘#’ or ‘;’ or C-style comments /* …. */
A simple example nsi script is shown here:
; Example.nsi ; ; Very simple example: all optional settings left as default. ; Installer asks user where to install, and drops copy of "Program.exe" there. ; Name the installer Name "Example" ; Set the installer output file name OutFile "ExampleInstaller.exe" ; Set the default installation directory InstallDir $PROGRAMFILES\Arrayjet\Sprint ; Set the text to prompt user to enter a directory DirText "This will install My Cool Program on your computer. Choose a directory" ; Specify all files needed for installation Section "MainSection" SEC01 ; Set output path to the installation directory, ; where INSTDIR = C:\Program Files\Arrayjet\Sprint SetOutPath $INSTDIR ;Create the installation directory CreateDirectory $INSTDIR ; Put file there File Program.exe File Text.txt SectionEnd
Save it as an .nsi file.
Compile the .nsi file
Open the .nsi file in the MakeNSISW tool and will automatically compile, highlighting any errors if there are any:
It will also create the installation executable for you:
Running this executable will create the directory C:\Program Files\Arrayjet\Sprint and insert the “Text.txt” and “Program.exe” files for you.
A more complicated example
The following nsi script, when compiled will generate an installation package that will create/install:
… ‘Welcome’/’Installation’/’Finish’ installation pages
… an complete un-install package
… software version information
… multiple files installed (exe, chm, pdf) from input folder
… a set of dlls for the the system32 folder
… the desired font
… new directories at chosen locations
… program shortcuts at chosen desktop/start menu locations
… required strings written to the registry
These functionlities are all self-documented inside the script:
# Auto-generated by EclipseNSIS Script Wizard # 14-Sep-2011 14:19:38 Name "Command Centre™ for Sprint" # General Symbol Definitions !define REGKEY "SOFTWARE\$(^Name)" !define VERSION 1.2.0 !define COMPANY Arrayjet !define URL http://www.arrayjet.co.uk # MUI Symbol Definitions !define MUI_ICON "resources\Common files\Small Instrument Software 1.0.ico" !define MUI_FINISHPAGE_NOAUTOCLOSE !define MUI_FINISHPAGE_RUN "$INSTDIR\Command Centre™ for Sprint v1.2.exe" !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico" !define MUI_UNFINISHPAGE_NOAUTOCLOSE # Included files !include Sections.nsh !include MUI.nsh # Variables Var StartMenuGroup # Installer pages !insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH !insertmacro MUI_UNPAGE_CONFIRM !insertmacro MUI_UNPAGE_INSTFILES # Installer languages !insertmacro MUI_LANGUAGE English # Installer attributes OutFile "Command Centre™ for Sprint v1.2.exe" InstallDir "$PROGRAMFILES\Arrayjet\Sprint Software" CRCCheck on XPStyle on ShowInstDetails show VIProductVersion 1.2.0.0 VIAddVersionKey ProductName "Sprint Software" VIAddVersionKey ProductVersion "${VERSION}" VIAddVersionKey CompanyName "${COMPANY}" VIAddVersionKey CompanyWebsite "${URL}" VIAddVersionKey FileVersion "${VERSION}" VIAddVersionKey FileDescription "" VIAddVersionKey LegalCopyright "" InstallDirRegKey HKLM "${REGKEY}" Path ShowUninstDetails show # Installer sections Section -MainInstallFolder SEC0000 SetOutPath $INSTDIR SetOverwrite on File "resources\Command Centre™ for Sprint v1.0 Help.chm" File "resources\Command Centre™ for Sprint v1.0 User Manual.pdf" File "resources\Command Centre™ for Sprint v1.2.exe" File "resources\Command Centre™ Release Notes v1.0.chm" File "resources\inst_param.aj" File "resources\Common files\runtime.aj" File "/oname=Sprint.ico" "resources\Common files\Small Instrument Software 1.0.ico" WriteRegStr HKLM "${REGKEY}\Components" MainInstallFolder 1 SectionEnd Section -windowsFiles SEC0001 SetOutPath $SYSDIR SetOverwrite try File "resources\Common files\msvcr71.dll" File "resources\Common files\msvcr70.dll" File "resources\Common files\msvcp71.dll" File "resources\Common files\MSVCI70.dll" File "resources\Common files\MFC71.dll" File "resources\Common files\mfc70.dll" WriteRegStr HKLM "${REGKEY}\Components" windowsFiles 1 SectionEnd Section -fonts SEC0002 SetOutPath $FONTS SetOverwrite on File "resources\Common files\lte50331.ttf" WriteRegStr HKLM "${REGKEY}\Components" fonts 1 SectionEnd Section -folders SEC0003 SetOutPath $INSTDIR SetOverwrite on CreateDirectory "LogFiles" CreateDirectory "Output Files" WriteRegStr HKLM "${REGKEY}\Components" folders 1 SectionEnd Section -shortcuts SEC0004 SetShellVarContext all SetOutPath "$SMPROGRAMS\$StartMenuGroup" CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Command Centre™ for Sprint.lnk" "$INSTDIR\Command Centre™ for Sprint v1.2.exe" "" "$INSTDIR\Sprint.ico" CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Help.lnk" "$INSTDIR\Command Centre™ for Sprint v1.0 Help.chm" CreateShortcut "$SMPROGRAMS\$StartMenuGroup\User Manual.lnk" "$INSTDIR\Command Centre™ for Sprint v1.0 User Manual.pdf" CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Uninstall.lnk" "$INSTDIR\Uninstall.exe" SetOutPath $DESKTOP CreateShortcut "$DESKTOP\Command Centre™ for Sprint.lnk" "$INSTDIR\Command Centre™ for Sprint v1.2.exe" "" "$INSTDIR\Sprint.ico" WriteRegStr HKLM "${REGKEY}\Components" shortcuts 1 SectionEnd Section -post SEC0005 WriteRegStr HKLM "${REGKEY}" Path $INSTDIR SetOutPath $INSTDIR WriteUninstaller $INSTDIR\uninstall.exe WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayName "$(^Name)" WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayVersion "${VERSION}" WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" Publisher "${COMPANY}" WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" URLInfoAbout "${URL}" WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayIcon $INSTDIR\uninstall.exe WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" UninstallString $INSTDIR\uninstall.exe WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoModify 1 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoRepair 1 SectionEnd # Macro for selecting uninstaller sections !macro SELECT_UNSECTION SECTION_NAME UNSECTION_ID Push $R0 ReadRegStr $R0 HKLM "${REGKEY}\Components" "${SECTION_NAME}" StrCmp $R0 1 0 next${UNSECTION_ID} !insertmacro SelectSection "${UNSECTION_ID}" GoTo done${UNSECTION_ID} next${UNSECTION_ID}: !insertmacro UnselectSection "${UNSECTION_ID}" done${UNSECTION_ID}: Pop $R0 !macroend # Uninstaller sections Section /o -un.folders UNSEC0004 RmDir "$INSTDIR\LogFiles" RmDir "$INSTDIR\Output Files" RmDir $SMPROGRAMS\$StartMenuGroup Delete /REBOOTOK $INSTDIR\* RmDir /REBOOTOK $INSTDIR Delete /REBOOTOK $INSTDIR\* RmDir /REBOOTOK $INSTDIR Delete $PROGRAMFILES\$INSTDIR\* RmDir $PROGRAMFILES\$INSTDIR RmDir $PROGRAMFILES\Arrayjet DeleteRegValue HKLM "${REGKEY}\Components" folders SectionEnd Section /o -un.fonts UNSEC0003 Delete /REBOOTOK $FONTS\lte50331.ttf DeleteRegValue HKLM "${REGKEY}\Components" fonts SectionEnd Section /o -un.windowsFiles UNSEC0002 Delete /REBOOTOK $SYSDIR\mfc70.dll Delete /REBOOTOK $SYSDIR\MFC71.dll Delete /REBOOTOK $SYSDIR\MSVCI70.dll Delete /REBOOTOK $SYSDIR\msvcp71.dll Delete /REBOOTOK $SYSDIR\msvcr70.dll Delete /REBOOTOK $SYSDIR\msvcr71.dll DeleteRegValue HKLM "${REGKEY}\Components" windowsFiles SectionEnd Section /o -un.MainInstallFolder UNSEC0001 Delete $INSTDIR\runtime.aj Delete $INSTDIR\inst_param.aj Delete "$INSTDIR\Command Centre™ Release Notes v1.0.chm" Delete /REBOOTOK "$INSTDIR\Command Centre™ for Sprint v1.2.exe" Delete /REBOOTOK "$INSTDIR\Command Centre™ for Sprint v1.0 User Manual.pdf" Delete /REBOOTOK "$INSTDIR\Command Centre™ for Sprint v1.0 Help.chm" Delete /REBOOTOK "$INSTDIR\Sprint.ico" DeleteRegValue HKLM "${REGKEY}\Components" MainInstallFolder SectionEnd Section /o -un.shortcuts UNSEC0000 SetShellVarContext all Delete "$SMPROGRAMS\$StartMenuGroup\Command Centre™ for Sprint.lnk" Delete "$SMPROGRAMS\$StartMenuGroup\Help.lnk" Delete "$SMPROGRAMS\$StartMenuGroup\User Manual.lnk" Delete "$SMPROGRAMS\$StartMenuGroup\Uninstall.lnk" Delete "$SMPROGRAMS\$StartMenuGroup\*.*" RMDir "$SMPROGRAMS\$StartMenuGroup" Delete "$DESKTOP\Command Centre™ for Sprint.lnk" DeleteRegValue HKLM "${REGKEY}\Components" shortcuts SectionEnd Section -un.post UNSEC0005 DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" Delete /REBOOTOK $INSTDIR\uninstall.exe DeleteRegValue HKLM "${REGKEY}" Path DeleteRegKey /IfEmpty HKLM "${REGKEY}\Components" DeleteRegKey /IfEmpty HKLM "${REGKEY}" RmDir /REBOOTOK $INSTDIR SectionEnd # Installer functions Function .onInit InitPluginsDir StrCpy $StartMenuGroup "Arrayjet" FunctionEnd # Uninstaller functions Function un.onInit ReadRegStr $INSTDIR HKLM "${REGKEY}" Path StrCpy $StartMenuGroup "Arrayjet" !insertmacro SELECT_UNSECTION shortcuts ${UNSEC0000} !insertmacro SELECT_UNSECTION MainInstallFolder ${UNSEC0001} !insertmacro SELECT_UNSECTION windowsFiles ${UNSEC0002} !insertmacro SELECT_UNSECTION fonts ${UNSEC0003} !insertmacro SELECT_UNSECTION folders ${UNSEC0004} FunctionEnd