Electron-builder: NSIS - Change $INSTDIR to a custom path

Created on 17 Aug 2017  Â·  8Comments  Â·  Source: electron-userland/electron-builder

Electron Builder - 19.22.1
Target - NSIS

I'm trying to change the default installation directory to custom(Ex: C:\MyApp) and remove default(C:\Program Files\MyApp).
package.json

{
    "win": {
      "target": "NSIS",
      "icon": "build/icon.ico"
    },
    "nsis": {
      "oneClick": false,
      "allowElevation": true,
      "allowToChangeInstallationDirectory": true,
      "createDesktopShortcut": true,
      "include": "build/installer.nsh"
    }
}

I used !macro preInit, but didn't work:
build/installer.nsh

!macro preInit
  StrCpy $INSTDIR "C:\MyApp"
!macroend

error

command StrCpy not valid outside Section or Function

It is possible to change default installation do C:\MyApp even if installer have only in elevation mode?

question

Most helpful comment

@hemavidal @develar
Just letting you know guys:
This would make autoUpdate always install to "C:\MyApp" (or your designated default dir) It happens on electron-builder 20.4.1.

Steps to reproduce:

  1. Make to version of your app, e.g. v0.1.0 and v.0.1.1
  2. Install v0.1.0 on somewhere other than "C:\MyApp", for example "C:\MyAppp"
  3. Let the autoupdate run.
  4. Autoupdate will install on "C:\MyApp"

All 8 comments

ReadRegStr $perMachineInstallationFolder HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation is used to detect previous path.

So, if you want to set custom path,

WriteRegStr SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"

can be used (note - not tested). A little bit hack, yes.

allowToChangeInstallationDirectory

not required in this case.

I resolved with this:

!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

@hemavidal Can I change ${INSTALL_REGISTRY_KEY} to a String,Beacuse I wan't know the regedit path,when I change it, Program will not create uninstall panel record

@hemavidal @develar
Just letting you know guys:
This would make autoUpdate always install to "C:\MyApp" (or your designated default dir) It happens on electron-builder 20.4.1.

Steps to reproduce:

  1. Make to version of your app, e.g. v0.1.0 and v.0.1.1
  2. Install v0.1.0 on somewhere other than "C:\MyApp", for example "C:\MyAppp"
  3. Let the autoupdate run.
  4. Autoupdate will install on "C:\MyApp"

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

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

I am also looking for this information

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

I am also looking for this information

I'm not sure if you can set the $INSTDIR

But, you can use nsExec to call echo %homedrive%%homepath% to get the user's home directory, which is C:\Users\{CURRENT_USERNAME}

Hi @hemavidal , can you share how did you find
command StrCpy not valid outside Section or Function error.
I strarted installation file .exe it freezed, installation does not progress. I can't find I can see error logs

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iklemm picture iklemm  Â·  3Comments

JohnWeisz picture JohnWeisz  Â·  3Comments

jhg picture jhg  Â·  3Comments

leo picture leo  Â·  3Comments

NPellet picture NPellet  Â·  3Comments