Skip to content

Commit a01f481

Browse files
committed
fix(nsis): install per current user even if run as administrator
1 parent a1bf645 commit a01f481

File tree

10 files changed

+33
-50
lines changed

10 files changed

+33
-50
lines changed

docs/Multi Platform Build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ To build rpm: `brew install rpm`.
4040

4141
To build app in distributable format for Linux:
4242
```
43-
sudo apt-get install --no-install-recommends -y icnsutils graphicsmagick xz-utils xorriso
43+
sudo apt-get install --no-install-recommends -y icnsutils graphicsmagick xz-utils
4444
```
4545

4646
To build rpm: `sudo apt-get install --no-install-recommends -y rpm`.

src/metadata.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,12 @@ export interface WinBuildOptions extends PlatformSpecificBuildOptions {
360360
*/
361361
export interface NsisOptions {
362362
/*
363-
Mark "all users" (per-machine) as default. Not recommended. Defaults to `false`.
363+
One-click installation. Defaults to `true`.
364+
*/
365+
readonly oneClick?: boolean | null
366+
367+
/*
368+
Install per all users (per-machine). Defaults to `false`.
364369
*/
365370
readonly perMachine?: boolean | null
366371

@@ -371,11 +376,6 @@ export interface NsisOptions {
371376

372377
readonly guid?: string | null
373378

374-
/*
375-
One-click installation. Defaults to `true`.
376-
*/
377-
readonly oneClick?: boolean | null
378-
379379
/*
380380
*boring installer only.* `MUI_HEADERIMAGE`, relative to the project directory. Defaults to `build/installerHeader.bmp`
381381
*/

src/targets/nsis.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ export default class NsisTarget extends Target {
8888
}
8989

9090
if (this.options.perMachine === true) {
91-
defines.MULTIUSER_INSTALLMODE_DEFAULT_ALLUSERS = null
92-
}
93-
else {
94-
defines.MULTIUSER_INSTALLMODE_DEFAULT_CURRENTUSER = null
91+
defines.INSTALL_MODE_PER_ALL_USERS = null
9592
}
9693

9794
if (this.options.allowElevation !== false) {

templates/nsis/NsisMultiUser.nsh

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Var RadioButtonLabel1
5656
!define MULTIUSER_INSTALLMODE_DISPLAYNAME "${PRODUCT_NAME} ${VERSION}"
5757
!endif
5858

59-
RequestExecutionLevel user ; will ask elevation only if necessary
59+
RequestExecutionLevel user
6060

6161
; Sets install mode to "per-machine" (all users).
6262
!macro MULTIUSER_INSTALLMODE_ALLUSERS UNINSTALLER_PREFIX UNINSTALLER_FUNCPREFIX
@@ -157,7 +157,6 @@ FunctionEnd
157157
!macroend
158158

159159
!macro MULTIUSER_INIT_CHECKS UNINSTALLER_PREFIX UNINSTALLER_FUNCPREFIX
160-
161160
;Installer initialization - check privileges and set default install mode
162161
!insertmacro MULTIUSER_INIT_TEXTS
163162

@@ -170,10 +169,10 @@ FunctionEnd
170169
StrCpy $IsAdmin 0
171170
${endif}
172171

173-
; Checks registry for previous installation path (both for upgrading, reinstall, or uninstall)
172+
# checks registry for previous installation path (both for upgrading, reinstall, or uninstall)
174173
StrCpy $HasPerMachineInstallation 0
175174
StrCpy $HasPerUserInstallation 0
176-
;Set installation mode to setting from a previous installation
175+
# set installation mode to setting from a previous installation
177176
ReadRegStr $PerMachineInstallationFolder HKLM "${MULTIUSER_INSTALLMODE_INSTALL_REGISTRY_KEY2}" "${MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_VALUENAME}"
178177
${if} $PerMachineInstallationFolder != ""
179178
StrCpy $HasPerMachineInstallation 1
@@ -189,24 +188,13 @@ FunctionEnd
189188
${elseif} $HasPerUserInstallation == "0" ; if there is only one installation... set it as default...
190189
${andif} $HasPerMachineInstallation == "1"
191190
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.AllUsers
192-
${else} ; if there is no installation, or there is both per-user and per-machine...
193-
${if} ${IsNT}
194-
${if} $IsAdmin == "1" ;If running as admin, default to per-machine installation if possible (unless default is forced by MULTIUSER_INSTALLMODE_DEFAULT_CURRENTUSER)
195-
!if MULTIUSER_INSTALLMODE_DEFAULT_CURRENTUSER
196-
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.CurrentUser
197-
!else
198-
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.AllUsers
199-
!endif
200-
${else} ;If not running as admin, default to per-user installation (unless default is forced by MULTIUSER_INSTALLMODE_DEFAULT_ALLUSERS and elevation is allowed MULTIUSER_INSTALLMODE_ALLOW_ELEVATION)
201-
!ifdef MULTIUSER_INSTALLMODE_DEFAULT_ALLUSERS & MULTIUSER_INSTALLMODE_ALLOW_ELEVATION
202-
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.AllUsers
203-
!else
204-
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.CurrentUser
205-
!endif
206-
${endif}
207-
${else} ; Not running Windows NT, (so it's Windows XP at best), so per-user installation not supported
208-
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.AllUsers
209-
${endif}
191+
${else}
192+
# if there is no installation, or there is both per-user and per-machine
193+
!ifdef INSTALL_MODE_PER_ALL_USERS
194+
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.AllUsers
195+
!else
196+
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.CurrentUser
197+
!endif
210198
${endif}
211199

212200
!macroend
@@ -215,7 +203,6 @@ FunctionEnd
215203
!verbose push
216204
!verbose 3
217205

218-
; se for inner (sub processo) e ainda assim não for admin... algo errado
219206
${If} ${UAC_IsInnerInstance}
220207
${AndIfNot} ${UAC_IsAdmin}
221208
;MessageBox MB_OK "This account doesn't have admin rights"
@@ -353,7 +340,6 @@ FunctionEnd
353340
${NSD_CreateRadioButton} 10u 50u 280u 20u "$9 ($0)"
354341
Pop $MultiUser.InstallModePage.CurrentUser
355342

356-
357343
nsDialogs::SetUserData $MultiUser.InstallModePage.AllUsers 1 ; Install for All Users (1, pra exibir o icone SHIELD de elevation)
358344
nsDialogs::SetUserData $MultiUser.InstallModePage.CurrentUser 0 ; Install for Single User (0 pra não exibir)
359345

@@ -369,8 +355,6 @@ FunctionEnd
369355
;${NSD_CreateLabel} 0u 130u 280u 20u ""
370356
;Pop $RadioButtonLabel3
371357

372-
373-
374358
${if} $MultiUser.InstallMode == "AllUsers" ; setting defaults
375359
SendMessage $MultiUser.InstallModePage.AllUsers ${BM_SETCHECK} ${BST_CHECKED} 0 ; set as default
376360
SendMessage $MultiUser.InstallModePage.AllUsers ${BM_CLICK} 0 0 ; trigger click event
@@ -473,13 +457,11 @@ FunctionEnd
473457
${endif}
474458
${endif}
475459
SendMessage $RadioButtonLabel1 ${WM_SETTEXT} 0 "STR:$7"
476-
;SendMessage $RadioButtonLabel2 ${WM_SETTEXT} 0 "STR:$8"
477-
;SendMessage $RadioButtonLabel3 ${WM_SETTEXT} 0 "STR:$9"
478460
FunctionEnd
479461

480462
!macroend
481463

482-
; SHCTX is the hive HKLM if SetShellVarContext all, or HKCU if SetShellVarContext user
464+
# SHCTX is the hive HKLM if SetShellVarContext all, or HKCU if SetShellVarContext user
483465
!macro MULTIUSER_RegistryAddInstallInfo
484466
!verbose push
485467
!verbose 3

templates/nsis/installer.nsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ Function .onInit
2929
Quit
3030
${EndIf}
3131

32-
!insertmacro MULTIUSER_INIT
3332
!insertmacro ALLOW_ONLY_ONE_INSTALLER_INSTACE
33+
!insertmacro MULTIUSER_INIT
3434

3535
InitPluginsDir
3636

test/fixtures/test-app-one/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"author": "Foo Bar <foo@example.com>",
99
"license": "MIT",
1010
"build": {
11-
"electronVersion": "1.2.3",
11+
"electronVersion": "1.2.6",
1212
"appId": "org.electron-builder.testApp",
1313
"app-category-type": "your.app.category.type",
1414
"iconUrl": "https://raw.githubusercontent.com/szwacz/electron-boilerplate/master/resources/windows/icon.ico",

test/fixtures/test-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"build": {
4-
"electronVersion": "1.2.3",
4+
"electronVersion": "1.2.6",
55
"appId": "org.electron-builder.testApp",
66
"app-category-type": "your.app.category.type",
77
"iconUrl": "https://raw.githubusercontent.com/szwacz/electron-boilerplate/master/resources/windows/icon.ico",

test/src/BuildTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ test("relative index", () => assertPack("test-app", allPlatforms(false), {
137137
}, true)
138138
}))
139139

140-
const electronVersion = "1.2.3"
140+
const electronVersion = "1.2.6"
141141

142142
test.ifNotWindows("electron version from electron-prebuilt dependency", () => assertPack("test-app-one", {
143143
targets: Platform.LINUX.createTarget(DIR_TARGET),

test/src/helpers/runTests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const rootDir = path.join(__dirname, "..", "..", "..")
1919
const testPackageDir = path.join(require("os").tmpdir(), "electron_builder_published")
2020
const testNodeModules = path.join(testPackageDir, "node_modules")
2121

22-
const electronVersion = "1.2.3"
22+
const electronVersion = "1.2.6"
2323

2424
async function main() {
2525
await BluebirdPromise.all([

test/src/winPackagerTest.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@ test("nsis", () => assertPack("test-app-one", _signed({
3434
}
3535
))
3636

37-
test.ifDevOrLinuxCi("nsis 32", () => assertPack("test-app-one", _signed({
38-
targets: Platform.WINDOWS.createTarget(["nsis"], Arch.ia32),
39-
}), {
40-
useTempDir: true,
37+
test.ifDevOrLinuxCi("nsis 32 perMachine", () => assertPack("test-app-one", {
38+
targets: Platform.WINDOWS.createTarget(["nsis"], Arch.ia32),
39+
devMetadata: {
40+
build: {
41+
nsis: {
42+
perMachine: true,
43+
}
44+
}
4145
}
42-
))
46+
}))
4347

4448
test.ifNotCiOsx("nsis boring", () => assertPack("test-app-one", _signed({
4549
targets: Platform.WINDOWS.createTarget(["nsis"]),

0 commit comments

Comments
 (0)