Automating Windows Installers with Nullsoft Scriptable Install System
Nullsoft Scriptable Install System (NSIS) is a free, open-source tool for creating Windows installers. It uses a compact scripting language to define installation logic, file operations, registry changes, shortcuts, uninstallation, and custom UI. NSIS is well-suited for automated builds because scripts are plain text and can be invoked from CI systems or build scripts.
Key automation features
- Script-driven configuration: installer behavior (files, registry, shortcuts, components, conditions) is defined in .nsi scripts for repeatable builds.
- Command-line compiler: makensis.exe compiles .nsi scripts non-interactively, enabling integration in build pipelines.
- Portable toolchain: NSIS is lightweight and can be installed on CI agents or run inside containers.
- Compression options: support for multiple compressors (zlib, bzip2, LZMA) to balance size and speed programmatically.
- Plugins and header files: modularize functionality (custom actions, service installers, registry helpers) for reuse across projects.
- Silent/unattended installs: support for /S and script-controlled silent mode to perform installs without UI—useful for automated testing and deployments.
- Uninstaller generation: NSIS scripts can automatically create uninstallers that reverse installed actions.
Common automation tasks and examples
- CI integration: add a build step that runs makensis with the .nsi file and archives the resulting .exe artifact.
- Versioning: inject build number/version into the installer via !define and command-line defines:
makensis -DVERSION=1.2.3 installer.nsi - Conditional files: include debug or platform-specific files using !ifdef / !ifndef in the script.
- Silent install test: run the produced installer with /S and verify file/registry changes in an automated test.
- Post-install actions: run scripts, register services, or call external tools during install/uninstall for end-to-end automation.
Best practices
- Keep scripts modular: split common functions into include files (.nsh) for reuse.
- Use defines for environment-specific values (paths, versions, build flags) so CI can override them.
- Test silent installs thoroughly—some plugins or custom pages may still require interaction.
- Sign installers in CI using a secure code-signing process (use secure variables or dedicated signing agents).
- Use LZMA compression for smaller installers unless build time is critical.
- Log install/uninstall actions to help automated tests validate outcomes.
Limitations and gotchas
- NSIS scripting is powerful but has a learning curve; complex logic can become hard to maintain.
- Limited native support for modern Windows features (UAC elevation must be handled explicitly).
- Plugins may be required for advanced tasks (e.g., service management, MSI interactions).
- Silent mode behavior can differ between custom pages—ensure scripts avoid interactive prompts when unattended installs are required.
Quick starter checklist
- Install NSIS on your build machine or CI image.
- Create a minimal installer.nsi (define name, output, files, sections).
- Compile with makensis (use -D defines for versioning).
- Run installer.exe with /S to test silent install.
- Add signing and artifact publishing steps in CI.
If you want, I can generate a minimal example .nsi script you can plug into a CI job and a sample CI step for GitHub Actions.
Leave a Reply