Electron-builder: Is there any way to specify a custom install path for Windows?

Created on 1 Sep 2016  Â·  12Comments  Â·  Source: electron-userland/electron-builder

  • Version: 6.3.3

  • Target: Mac and Windows (with a Squirrel installer)

We're transitioning from an NW.js app where the app is installed in AppData/Roaming and the localStorage is placed in AppData/Local but Electron/Squirrel is installed to AppData/Local and localStorage is placed in AppData/Roaming (opposite). When our users update from one to the other, we don't want the localStorage being deleted when the Electron app is installed there. So can we customize these paths (so we can put our Electron app & localStorage in the same locations as before)?

question

All 12 comments

I recommend you to migrate your data and follow target (NSIS or Squirrel.Windows) conventions.

Squirrel.Windows — handle --squirrel-install and perform migration. If Squirrel.Windows will clear directory before this event, I can fix it for you.

NSIS — add your customInit. customInit, not customInstall because https://github.com/electron-userland/electron-builder/blob/master/templates/nsis/install.nsh#L82 — i.e. called after standard install and, so, directory may be cleared before your custom code. See http://nsis.sourceforge.net/Category:Disk,_Path_%26_File_Functions

I recommend NSIS instead of Squirrel.Windows. NSIS will be soon default target — once #529 resolved.

So can we customize these paths

If you don't want to change layout, NSIS is the only solution. Currently, no options to customise it, but I can fix it for you if need (as high priority task).

Squirrel.Windows cannot be customised as NSIS — we can change Squirrel.Windows code, but no one can promise that it will work correctly.

If you don't want to use NSIS because of #529 — I can fix it next week :)

OK thanks. We need a Squirrel installer. We're currently looking at copying stuff around using a batch script (spawned by the old app before updating) and we think we almost have it. If not, we'll use the --squirrel-install event. Thanks!

@develar, Is it already implemented to change installation path for NSIS? It will be great regarding end-users who already using squirrel updater and gonna migrate to nsis (for example pinned icon to task bar will have invalid path missing /Programs/ level).

@cumajkeee User can if https://github.com/electron-userland/electron-builder/wiki/Options#NsisOptions-allowToChangeInstallationDirectory set to true. Do you mean programmatically?

@develar, yes, I mean programmatically

build/installer.nsh

 !macro preInit
    SetRegView 64
    WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
    WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
    SetRegView 32
    WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
    WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
 !macroend

then include this file in package.json

Does it _have_ to be in build? That folder is ignored by git, so it's breaks version control.

@davidAlittle You can add a webpack Copy plugin or gulp/grunt task (depending on the tooling you use) to copy that file inside build/. That's what I'm doing right now.

@amaurymartiny adding !build/installer.nsh to my .gitignore was sufficient. Thanks for the tip though!

yes,ialays
sye
; Script generated by the HM NIS Edit Script Wizard.

; HM NIS Edit Wizard helper defines custom install default dir
!macro preInit
SetRegView 64
WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "D:\electron-builder-start-exe"
WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "D:\electron-builder-start-exe"
SetRegView 32
WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "D:\electron-builder-start-exe"
WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "D:\electron-builder-start-exe"
!macroend

Does anyone knows what variable to use such that i can set the $INSTDIR path as "C:\Users{CURRENT_USERNAME}"

Where {CURRENT_USERNAME} is the currently logged in username.

Thanks

Was this page helpful?
0 / 5 - 0 ratings