Skip to content

Commit

Permalink
fix(nsis): per-machine installs must properly elevate during silent i…
Browse files Browse the repository at this point in the history
…nstall/updates (#6450)

* fix(nsis): fix per-machine installs

Add @krisdages changes from PR #6438 to elevate silent per-machine installs.
Remove PR #6073 that incorrectly elevates all per-machine installs, breaking interactive per-machine installs.

Closes #6425, #5468

Co-authored-by: Robert Patrick
Co-authored-by: Kris Dages
  • Loading branch information
robertpatrick committed Nov 30, 2021
1 parent 41a59f9 commit 661a652
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .changeset/famous-games-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"app-builder-lib": patch
"electron-updater": patch
---

fix(nsis): fix per-machine installs to properly elevate during silent install/updates
26 changes: 26 additions & 0 deletions packages/app-builder-lib/templates/nsis/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,32 @@ FunctionEnd

Section "install"
!ifndef BUILD_UNINSTALLER
# If we're running a silent upgrade of a per-machine installation, elevate so extracting the new app will succeed.
# For a non-silent install, the elevation will be triggered when the install mode is selected in the UI,
# but that won't be executed when silent.
!ifndef INSTALL_MODE_PER_ALL_USERS
!ifndef ONE_CLICK
${if} $hasPerMachineInstallation == "1" # set in onInit by initMultiUser
${andIf} ${Silent}
${ifNot} ${UAC_IsAdmin}
ShowWindow $HWNDPARENT ${SW_HIDE}
!insertmacro UAC_RunElevated
${Switch} $0
${Case} 0
${Break}
${Case} 1223 ;user aborted
${Break}
${Default}
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Unable to elevate, error $0"
${Break}
${EndSwitch}
Quit
${else}
!insertmacro setInstallModePerAllUsers
${endIf}
${endIf}
!endif
!endif
!include "installSection.nsh"
!endif
SectionEnd
Expand Down
18 changes: 2 additions & 16 deletions packages/electron-updater/src/BaseUpdater.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as fs from "fs"
import * as path from "path"
import { AllPublishOptions } from "builder-util-runtime"
import { AppAdapter } from "./AppAdapter"
import { AppUpdater, DownloadExecutorTask } from "./AppUpdater"
Expand Down Expand Up @@ -59,24 +57,12 @@ export abstract class BaseUpdater extends AppUpdater {
this.quitAndInstallCalled = true

try {
let installPathRequiresElevation = false
if (process.platform === "win32") {
try {
const accessTestPath = path.join(path.dirname(process.execPath), `access-${Math.floor(Math.random() * 100)}.tmp`)
fs.writeFileSync(accessTestPath, " ")
fs.rmSync(accessTestPath)
} catch (err) {
// Require admin rights if needed
installPathRequiresElevation = true
}
}

this._logger.info(`Install: isSilent: ${isSilent}, isForceRunAfter: ${isForceRunAfter}, installPathRequiresElevation: ${installPathRequiresElevation}`)
this._logger.info(`Install: isSilent: ${isSilent}, isForceRunAfter: ${isForceRunAfter}`)
return this.doInstall({
installerPath,
isSilent,
isForceRunAfter,
isAdminRightsRequired: installPathRequiresElevation || downloadedFileInfo.isAdminRightsRequired,
isAdminRightsRequired: downloadedFileInfo.isAdminRightsRequired,
})
} catch (e) {
this.dispatchError(e)
Expand Down

0 comments on commit 661a652

Please sign in to comment.