Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSIS all users installation auto-update #2363

Closed
Egorikhin opened this issue Dec 6, 2017 · 17 comments
Closed

NSIS all users installation auto-update #2363

Egorikhin opened this issue Dec 6, 2017 · 17 comments

Comments

@Egorikhin
Copy link
Contributor

Egorikhin commented Dec 6, 2017

  • electron-builder version:
    19.47.1

  • electron-updater version
    2.16.3

  • Target:
    win

I'm facing the issue with updating application installed to the Program Files folder.
I have oneClick: false in config and i'm installing updates with:

        setImmediate(() => {
            app.removeAllListeners("window-all-closed");
            autoUpdater.quitAndInstall(true, true);
        });

So when I'm trying to update application running under not admin account, it show UAC notificaton to enable old-uninstaller.exe execution. After I click on Yes it successfully deletes everything from application folder in Program Files but not installs new one. Altough, when I'm trying to update it under admin account it will be updated successfully.

Maybe it's relevant to this issue.
Could you please take a look on it or maybe suggest where should i look?

@Egorikhin Egorikhin changed the title NSIS auto-update NSIS all users installation auto-update Dec 6, 2017
@Egorikhin
Copy link
Contributor Author

Ok, figured out myself.
You can use this customInit script in order to make it work as expected:

!macro customInit
    ${if} $installMode == "all"
        ${IfNot} ${UAC_IsAdmin}
            ShowWindow $HWNDPARENT ${SW_HIDE}
            !insertmacro UAC_RunElevated
            Quit
        ${endif}
    ${endif}
!macroend

@develar
Copy link
Member

develar commented Dec 11, 2017

Better to prepare PR. Anyway, thanks for solution.

@Egorikhin
Copy link
Contributor Author

Egorikhin commented Dec 11, 2017

I don't know if it will be the correct code to fix in the PR, so i'll try to ask here

In the multiUser.nsh on line 45 there is the following code:

  !macro setInstallModePerAllUsers
    StrCpy $installMode all
    SetShellVarContext all

    !ifdef BUILD_UNINSTALLER # <--
      ${IfNot} ${UAC_IsAdmin}
        ShowWindow $HWNDPARENT ${SW_HIDE}
        !insertmacro UAC_RunElevated
        Quit
      ${endif}
    !endif # <--

If we delete code with arrows, it will work as expected, but I'm not sure if it's correct to delete this.
Could you please assist me on this?

@develar
Copy link
Member

develar commented Dec 11, 2017

Cannot answer right now, UAC is quite complicated, need to deep reinvestigate. Could you please provide your full nsis config?

@Egorikhin
Copy link
Contributor Author

config:

    "nsis": {
        "oneClick": false,
        "allowToChangeInstallationDirectory": true,
        "include": "./configuration/zzz/include.nsh",
        "license": "./configuration/zzz/license.rtf",
        "installerHeader": "./configuration/zzz/header.bmp",
        "installerSidebar": "./configuration/zzz/side_bar.bmp"
    }, 

include.nsh:

!macro customUnInit
  ${IfNot} ${Silent}
    MessageBox MB_YESNO "Uninstalling the application will delete all related settings. Do you want to continue?" IDYES true IDNO false
    false:  
      Quit
    true:
      RMDir /r "$PROFILE\AppData\Roaming\zzz"
      DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "zzz"
  ${EndIf}
!macroend

!macro customInit
    ${if} $installMode == "all"
        ${IfNot} ${UAC_IsAdmin}
            ShowWindow $HWNDPARENT ${SW_HIDE}
            !insertmacro UAC_RunElevated
            Quit
        ${endif}
    ${endif}
!macroend

@develar
Copy link
Member

develar commented Dec 11, 2017

Yeah.... problem is that allowToChangeInstallationDirectory is set to true, but our scripts right now not aware about it (as in case of explicit perMachine), it seems.

@Egorikhin
Copy link
Contributor Author

Egorikhin commented Dec 11, 2017

I think that this problem is caused by the fact that silent installer is not aware of what permission it has when it tries to install update.
As I can see, uninstallation process is triggered by this line:
ExecWait '"$PLUGINSDIR\old-uninstaller.exe" /S /KEEP_APP_DATA $0 _?=$R1'
But installation (i.e. extracting files to directory) is performed via Nsis7z::Extract "${FILE}"
In the first case, OS will promt user if he's sure to run this .exe under admin rights, but in the second case it will just not extract anything into it without any complains.

@chrisbruford
Copy link

@develar was this resolved then? I've had to turn off silent updates in my application as it wouldn't update without the UAC prompt and was waiting for a solution on here?

@develar
Copy link
Member

develar commented Jul 31, 2018

@chrisbruford Please try latest versions. Should be fixed (and I have manually checked per-machine installation).

@maxannear
Copy link

@develar I'm Still seeing this with electron-builder 20.39.0. I used @Egorikhin's customInit and it works correctly.

My setttings

"nsis": {
      "include": "./build/installer.nsh",
      "oneClick": false,
      "perMachine": false,
      "createDesktopShortcut": true,
      "createStartMenuShortcut": true
    }

@Nkay
Copy link

Nkay commented May 27, 2019

@develar I've got this problem too. I think there are 2 paths here:
perMachine: true
and
perMachine: false

with allowToChangeInstallationDirectory set.
From what I read in the other Issues, perMachine: true works fine now, but if perMachine is false and the user chose an other installation path, after an update, there are some files missing in the chosen path (like the uninstaller). Clearly, the uninstall does not work when the file is missing.

@Nkay
Copy link

Nkay commented May 27, 2019

A little more description:

"nsis": {
      "oneClick": false,
      "perMachine": false,
      "allowElevation": true,
      "allowToChangeInstallationDirectory": true,
      "menuCategory": true,
      "runAfterFinish": false
    },

The problem exists with the per-user installation.

  "devDependencies": {
    "electron": "3.0.4",
    "electron-builder": "20.39.0"
  },
  "dependencies": {
    "electron-log": "3.0.5",
    "electron-updater": "4.0.6"
}

@JohnTendik
Copy link
Contributor

We ran into the same issue, however our solution was to force administrative privileges with
"requestedExecutionLevel": "highestAvailable"

@delewis13
Copy link

delewis13 commented Oct 16, 2021

UPDATE

I had an issue that wasn't solved by any of the above. In the end, it turned out that having productName the same as my artifactName was causing the issue. More info here: #6329

ORIGINAL

Have tried every combination of config options, the custom include.nsh and can't for the life of me get the autoUpdate to work. Every time it simply deletes my old install, and doesn't install the updated version. Issue here: #6329

Each time, it fails to run due to permissions, so runs in elevate instead, running C;\Users\<USER>\AppData\Local\<APP_NAME>-updater\pending\<APP_NAME>exe --updated /S, which uninstalls everything and doesn't update. If I manually re-run the same command again, it successfully installs.

Have tried with:

  nsis: {
     oneClick: true
  },
  nsis: {
    oneClick: false,
    perMachine: true,
  },
  nsis: {
    oneClick: false,
    perMachine: false,
  },
  nsis: {
    include: './build/include.nsh',
    oneClick: false,
    perMachine: false,
  },
  nsis: {
    include: './build/include.nsh',
    oneClick: false,
    perMachine: true,
  },

Same result, every time.

@robertpatrick
Copy link
Contributor

robertpatrick commented Nov 24, 2021

@develar I am still seeing this issue with electron-builder 22.14.7 and electron-updater 4.6.2. My NSIS config is pretty simple:

    "nsis": {
      "oneClick": false,
      "allowToChangeInstallationDirectory": true
    },

When we set autoUpdater.autoInstallOnAppQuit to true (after having selected install for all users when I installed the app) and quit the app normally (via app.quit()), I see the UAC prompt for old-installer.exe and the app is uninstalled (though it is leaving both the Start Menu and Desktop shortcuts orphaned) but the new version installer never runs.

I have verified that my name, productName, and build.appId fields of my package.json file are all different so I don't think that #6329 is applicable to my situation.

@robertpatrick
Copy link
Contributor

@develar nevermind, user error... We were doing something to interrupt the app.quit() cycle in our app.on('will-quit') listener. Once I fixed that, Windows autoInstallOnAppQuit is working in electron-updater@4.6.2. Just need to get #6425 addressed and we all of our autoUpdater-related issues will be resolved!

@denishowe
Copy link

our solution was to force administrative privileges with "requestedExecutionLevel": "highestAvailable"

Running the app as (an) administrator seems like an extreme solution to get auto-update to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants