3
votes

I am using Electron Builder to generate an NSIS installer for windows. I need the installer to create a shortcut in the startup menu.

How can I do that?

This is Electron Builder documentation about NSIS Scripts. https://www.electron.build/configuration/nsis#custom-nsis-script

Where should I put code to be executed after installing the application?

2

2 Answers

8
votes

I was able to do this by putting the code that creates the shortcut in side the customInstall macro in a custom instllaer script for NSIS

In package.json

"build": {
  "nsis": {
      "include": "build/installer.nsh",
  },

This is to be able to use a custom script.

And in the build/installer.nsh

!macro customInstall
      CreateShortCut "$SMSTARTUP\filename.lnk" "$INSTDIR\filename.exe"
!macroend
2
votes

Use the "createStartMenuShortcut" option in the top-level nsis key in your electron-builder config:

"build": {
  "nsis": {
    "createStartMenuShortcut": true,
  },
  //Rest of the config
}

You can find more config options in the docs