Skip to content

Porting from NSIS

Carlos Hernandez edited this page Jul 15, 2026 · 5 revisions

Porting from NSIS

If you already ship a Windows installer written in NSIS, this page maps the constructs you use onto embala's Setup-Exe backend and its embala.* API. The worked example throughout is a fictional but representative VPN client — "Acme VPN" — whose installer.nsis has the shape of a typical non-trivial MUI2 script: a WebView2 dependency, previous-install detection, a machine-wide PATH edit, a Windows service, and an opt-in "delete all app data" uninstall checkbox.

The honest framing up front: most of an NSIS script is the 80% embala already does declaratively. The MUI pages, the uninstaller, the ARP entry, the shortcuts, and reproducible branding are [setup] fields — you don't script them. What you do port by hand is the conditional logic NSIS expresses with ${If} / plugins: registry probes, ExecWait, and PATH edits. Those become a raw script in Lua. See the not-covered list at the end for the parts that don't map.

Construct mapping

NSIS construct embala equivalent
MUI_PAGE_WELCOME / LICENSE / DIRECTORY / INSTFILES / FINISH Declarative [setup] — the wizard pages are generated (welcome, license, directory, progress, finish). No script needed.
MUI_ICON / MUI_UNICON [setup].icon (PNG or ICO) — patched into setup.exe and the inherited uninstall.exe.
VIProductVersion / VIAddVersionKey Automatic VERSIONINFO built from [package] (ProductName, CompanyName, FileDescription, versions, LegalCopyright). No field to set.
MUI_WELCOMEFINISHPAGE_BITMAP [setup].banner (a BMP), rendered on the welcome and finish pages.
InstallDir "$PROGRAMFILES64\…" + SetShellVarContext all + REG_ROOT HKLM install-mode = "per-machine" — picks Program Files, the all-users Start Menu, HKLM, and UAC elevation together.
CreateShortCut "$SMPROGRAMS\…" / "$DESKTOP\…" [setup].shortcuts = [{ name, target, location = "start-menu" | "desktop" }].
WriteRegStr embala.registry.set{ hive, key, name, value, kind? } (journaled + reversed on uninstall).
ReadRegStr embala.registry.get{ hive, key, name? } → string / integer / nil.
DeleteRegValue / DeleteRegKey embala.registry.delete{ hive, key, name? } (destructive, not reversed).
EnVar::AddValueEx "path" "$INSTDIR" embala.env.set{ name = "PATH", value = …, scope = "machine" } (writes REG_EXPAND_SZ and broadcasts the change; reversed on uninstall).
ExecWait '"$INSTDIR\app.exe" …' embala.exec{ cmd, args, wait = true } → { code, stdout, stderr } (not journaled — reversal is yours).
ShellExecAsUser::ShellExecAsUser (launch de-elevated) embala.exec + an explorer.exe delegate launch or a run-once scheduled task — see Idiom 4.
WriteUninstaller + Section Uninstall Automatic: every journaled call is replayed LIFO on uninstall; uninstall-script adds custom teardown.
un.DeleteDataPage custom nsDialogs checkbox [setup].uninstall-options = [{ id, label, default? }] + embala.ui.selected(id) in uninstall.lua.
MessageBox, ${If}, LogicLib, StrCpy Plain Lua — if, string ops, embala.log.

Acme VPN declares this much with no install script at all:

[package]
name = "acme-vpn"
display-name = "Acme VPN"
version = "0.70.1"
identifier = "com.example.acmevpn"
publisher = "Acme Inc."
description = "Connect your devices into a secure WireGuard-based overlay network."
copyright = "Acme Inc., 2022"

[setup]
arch = "x86_64"
install-mode = "per-machine"
main-executable = "acme-vpn-ui.exe"
icon = "ui/build/windows/icon.ico"
banner = "ui/build/banner.bmp"
license = "LICENSE"
files = [
  { src = "dist/windows_amd64/acme-vpn.exe", dest = "acme-vpn.exe" },
  { src = "dist/windows_amd64/acme-vpn-ui.exe", dest = "acme-vpn-ui.exe" },
  { src = "dist/windows_amd64/wintun.dll", dest = "wintun.dll" },
]
shortcuts = [
  { name = "Acme VPN", target = "acme-vpn-ui.exe", location = "start-menu" },
  { name = "Acme VPN", target = "acme-vpn-ui.exe", location = "desktop" },
]
uninstall-options = [
  { id = "purge-data", label = "Delete all Acme VPN configuration and state data", default = false },
]
script = "install.lua"
uninstall-script = "uninstall.lua"

The script/uninstall-script escape hatches carry the conditional logic below. (A raw script can't be combined with main-executable, shortcuts, or components — Acme VPN would fold those shortcuts into install.lua instead. The uninstall-options are allowed alongside a raw script; they concern uninstall, not install lowering.)

The three branding constructs — icon (MUI_ICON), banner (MUI_WELCOMEFINISHPAGE_BITMAP), and the automatic VERSIONINFO (VIProductVersion / VIAddVersionKey) — are declared, never scripted. Here is what those fields render to: the wizard welcome page carries the banner and title-bar icon, and setup.exe's Details tab carries the VERSIONINFO built straight from [package]:

Acme VPN wizard welcome page: gradient banner in the left column, branded title-bar icon setup.exe Properties → Details: ProductName "Acme VPN", FileVersion 0.70.1.0, Copyright "Acme Inc., 2022"

Idiom 1 — WebView2 presence check

NSIS probes two registry markers, and only downloads + silently installs the Evergreen bootstrapper when neither is present:

-- install.lua — ensure the Edge WebView2 runtime is present.
local WV2_CLIENT = "{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}"

local function webview2_present()
  -- Per-machine marker (shipped with Edge or admin-installed)...
  if embala.registry.get{
    hive = "HKLM",
    key = [[SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\]] .. WV2_CLIENT,
    name = "pv",
  } then
    return true
  end
  -- ...else the per-user marker.
  return embala.registry.get{
    hive = "HKCU",
    key = [[Software\Microsoft\EdgeUpdate\Clients\]] .. WV2_CLIENT,
    name = "pv",
  } ~= nil
end

if not webview2_present() then
  embala.log("Installing the WebView2 runtime")
  local setup = embala.install_dir .. "\\MicrosoftEdgeWebview2Setup.exe"
  -- Pin a sha256 you host — the evergreen bootstrapper's bytes change over time,
  -- and download has no unchecked mode.
  embala.download{
    url = "https://example.com/MicrosoftEdgeWebview2Setup.exe",
    sha256 = "0000000000000000000000000000000000000000000000000000000000000000",
    dest = setup,
  }
  local r = embala.exec{ cmd = setup, args = { "/silent", "/install" }, wait = true }
  if r.code ~= 0 then
    embala.log("WebView2 bootstrapper exited " .. r.code)
  end
end

Two honest notes versus the NSIS macro: embala.download requires a sha256 (there is no unchecked fetch), so you host a pinned bootstrapper build rather than hot-linking the always-moving evergreen URL; and registry.get runs before any wizard page — exactly where a dependency check belongs — because it is not gated (see Lua-Scripting).

Idiom 2 — detect and remove a previous install

NSIS reads the old UninstallString and runs it silently before upgrading. embala's UninstallString is a plain quoted path to uninstall.exe, so you read it, strip the quotes, and exec it with /S:

-- install.lua — remove any previously installed Acme VPN first.
local prev = embala.registry.get{
  hive = "HKLM",
  key = [[Software\Microsoft\Windows\CurrentVersion\Uninstall\com.example.acmevpn]],
  name = "UninstallString",
}
if prev then
  local exe = prev:match('^"(.-)"') or prev  -- drop surrounding quotes if present
  embala.log("Removing the previous Acme VPN install")
  -- /S runs the uninstaller headless; it applies the option defaults.
  embala.exec{ cmd = exe, args = { "/S" }, wait = true }
end

The ARP key is …\Uninstall\<identifier> — embala registers under [package].identifier, not the display name, so the key is com.example.acmevpn here rather than NSIS's $(^NAME).

Idiom 3 — the delete-data uninstall option

Acme VPN's un.DeleteDataPage is a custom nsDialogs page with one checkbox that gates an RMDir /r of the data directory. In embala that checkbox is a declared uninstall-option (shown in the confirm dialog) — the whole un.DeleteDataPage collapses to that one checkbox on the generated confirm dialog:

Acme VPN uninstall confirm dialog: branded icon and the "Delete all Acme VPN configuration and state data" checkbox

The teardown reads it:

-- uninstall.lua — additive teardown; the engine still replays install.log after.
embala.exec{ cmd = embala.install_dir .. "\\acme-vpn.exe", args = { "service", "stop" }, wait = true }
embala.exec{ cmd = embala.install_dir .. "\\acme-vpn.exe", args = { "service", "uninstall" }, wait = true }

if embala.ui.selected("purge-data") then
  embala.log("Deleting all Acme VPN data")
  embala.fs.remove_tree("C:\\ProgramData\\AcmeVPN")
end

ui.selected("purge-data") is true when the user ticked the box in the confirm dialog, when /options=purge-data was passed to uninstall.exe, or when the option's default is true. Querying an id that no uninstall-options entry declared is a hard error — a typo fails loud. The service stop/uninstall runs first because the log replay that follows removes the files the service locks.

Idiom 4 — launch the app de-elevated (ShellExecAsUser)

A per-machine install runs elevated, and anything the elevated installer spawns — including the finish page's "Run …" checkbox — inherits the admin token. NSIS scripts reach for the ShellExecAsUser plugin so the app starts as the plain desktop user instead. embala has no dedicated call for this, but Windows itself provides two well-worn routes, both driven from install.lua with plain embala.exec. (On a per-user install the installer is never elevated, so none of this is needed.)

Route 1 — delegate the launch to Explorer. The user's explorer.exe runs with their normal token; asking it to open the exe launches with that token, not the installer's:

-- install.lua — start the app as the logged-in user, not as admin.
embala.exec{
  cmd = "explorer.exe",
  args = { embala.install_dir .. "\\acme-vpn-ui.exe" },
  wait = false,
}

One line, no dependencies — but it cannot pass arguments to the app, and it needs a running shell (any interactive desktop has one).

Route 2 — a run-once scheduled task, via PowerShell. A task registered without an elevated run level executes with the user's limited token even when it is created by an elevated process, and -Argument carries real arguments:

-- install.lua — de-elevated launch with arguments.
local exe = embala.install_dir .. "\\acme-vpn-ui.exe"
embala.exec{
  cmd = "powershell.exe",
  args = {
    "-NoProfile", "-WindowStyle", "Hidden", "-Command", ([[
      $a = New-ScheduledTaskAction -Execute '%s' -Argument '--minimized'
      Register-ScheduledTask -TaskName AcmeVpnLaunch -Action $a -Force | Out-Null
      Start-ScheduledTask -TaskName AcmeVpnLaunch
      Start-Sleep -Seconds 2
      Unregister-ScheduledTask -TaskName AcmeVpnLaunch -Confirm:$false
    ]]):format(exe),
  },
  wait = true,
}

Both routes were verified from a genuinely elevated (high-integrity) process on Windows 11: the launched app reports a medium-integrity token, and Route 2 delivers its -Argument intact. Caveats worth knowing: the single quotes around '%s' survive spaces in the install path but not a literal ' in it; the launch happens when install.lua runs (the script finishes before the finish page shows), so pair it with your own "start now?" logic rather than the finish-page checkbox; and the scheduled task briefly exists under a visible name — keep it specific to your app to avoid collisions.

What's not covered

These NSIS constructs have no embala equivalent — they're either out of scope or belong to NSIS's plugin ecosystem:

  • Arbitrary custom pages. embala's only user-facing choices are the declarative pages (welcome/license/directory/components/finish) and the uninstall-option checkboxes. A custom nsDialogs page with text fields, radio groups, or bespoke layout (anything beyond a checkbox) does not port — there is no install-time page-authoring API.
  • NSIS plugins. EnVar, ShellExecAsUser, nsExec, nsDialogs, and the rest are NSIS-specific. Their common uses map to the API (EnVar → env.set, an ExecWait-style launch → exec, ShellExecAsUser → Idiom 4), but a plugin call with no API counterpart or scriptable Windows equivalent has no direct replacement.
  • _?= in-place uninstall and manual SetRegView juggling. embala's uninstaller self-deletes on its own and doesn't expose registry-view control; reads and writes use the hive you name (HKCU/HKLM) directly.
  • Install-time /options=. The flag is uninstall-only; there is no install-time selectable-options mechanism beyond components.

For the full API surface and what is and isn't reversed, see Lua-Scripting; for the [setup] fields, Configuration-Reference; for the wizard, CLI flags, branding, and uninstall flow, Setup-Exe.

Clone this wiki locally