Skip to content

Commit 873ff8a

Browse files
committed
windows: allow non-admin single-user install
1 parent beea323 commit 873ff8a

File tree

1 file changed

+29
-43
lines changed

1 file changed

+29
-43
lines changed

packaging/windows/pcbasic.nsi

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111
!define INSTDIR_REG_ROOT "HKLM"
1212
!define INSTDIR_REG_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\PC-BASIC"
1313

14-
;--------------------------------
15-
;Include Modern UI
1614

15+
; multiuser, modern UI
16+
17+
!define MULTIUSER_EXECUTIONLEVEL Highest
18+
!define MULTIUSER_MUI
19+
!define MULTIUSER_INSTALLMODE_COMMANDLINE
20+
!define MULTIUSER_INSTALLMODE_INSTDIR "PC-BASIC"
21+
!include "MultiUser.nsh"
1722
!include "MUI2.nsh"
1823
!include "AdvUninstLog.nsh"
1924
;
@@ -25,21 +30,6 @@
2530
Name "PC-BASIC 3.23"
2631
OutFile "pcbasic-win32.exe"
2732

28-
29-
30-
31-
32-
33-
;Default installation folder
34-
InstallDir "$programfiles\PC-BASIC"
35-
;Get installation folder from registry if available
36-
InstallDirRegKey ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "InstallDir"
37-
38-
;Request application privileges for Windows Vista
39-
;RequestExecutionLevel user
40-
41-
RequestExecutionLevel admin ;Require admin rights on NT6+ (When UAC is turned on)
42-
4333
!include LogicLib.nsh
4434

4535

@@ -53,6 +43,8 @@ RequestExecutionLevel admin ;Require admin rights on NT6+ (When UAC is turned on
5343
;Variables
5444

5545
Var StartMenuFolder
46+
Var Shortcuts
47+
5648

5749
;--------------------------------
5850
;Interface Settings
@@ -67,6 +59,9 @@ Var StartMenuFolder
6759
;--------------------------------
6860
;Pages
6961

62+
63+
!insertmacro MULTIUSER_PAGE_INSTALLMODE
64+
7065
!insertmacro UNATTENDED_UNINSTALL
7166
;!insertmacro INTERACTIVE_UNINSTALL
7267

@@ -107,37 +102,21 @@ Section "PC-BASIC" SecDummy
107102
SetOutPath "$PROFILE"
108103
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\PC-BASIC.lnk" "$INSTDIR\pcbasic.exe"
109104

105+
; workaround as multiuser doesn't seem to get the right location for shortcuts if an admin user installs 'just for me'
106+
WriteRegStr HKCU "Software\PC-BASIC" "Shortcuts" "$SMPROGRAMS\$StartMenuFolder"
107+
110108

111109
!insertmacro MUI_STARTMENU_WRITE_END
112110
SectionEnd
113111

114-
;--------------------------------
115-
;Descriptions
116-
117-
;Language strings
118-
; LangString DESC_SecDummy ${LANG_ENGLISH} "Main section."
119-
120-
;Assign language strings to sections
121-
; !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
122-
; !insertmacro MUI_DESCRIPTION_TEXT ${SecDummy} $(DESC_SecDummy)
123-
; !insertmacro MUI_FUNCTION_DESCRIPTION_END
124-
125-
126112
;--------------------------------
127113
;Uninstaller Section
128114

129115

130116
Function .onInit
131-
;prepare log always within .onInit function
132-
133-
UserInfo::GetAccountType
134-
pop $0
135-
${If} $0 != "admin" ;Require admin rights on NT4+
136-
MessageBox mb_iconstop "The PC-BASIC installer requires administrator rights, which you appear not to have."
137-
SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
138-
Quit
139-
${EndIf}
117+
!insertmacro MULTIUSER_INIT
140118

119+
;prepare log always within .onInit function
141120
!insertmacro UNINSTALL.LOG_PREPARE_INSTALL
142121
FunctionEnd
143122

@@ -155,16 +134,23 @@ Section UnInstall
155134
!insertmacro UNINSTALL.LOG_END_UNINSTALL
156135

157136
!insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
158-
Delete "$SMPROGRAMS\$StartMenuFolder\PC-BASIC.lnk"
159-
Delete "$SMPROGRAMS\$StartMenuFolder\Documentation.lnk"
160-
Delete "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk"
161-
RMDir "$SMPROGRAMS\$StartMenuFolder"
137+
138+
; workaround as multiuser doesn't seem to get the right location for shortcuts if an admin user installs 'just for me'
139+
ReadRegStr $Shortcuts HKCU "Software\PC-BASIC" "Shortcuts"
140+
141+
Delete "$Shortcuts\PC-BASIC.lnk"
142+
Delete "$Shortcuts\Documentation.lnk"
143+
Delete "$Shortcuts\Uninstall.lnk"
144+
RMDir "$Shortcuts"
162145

163-
DeleteRegKey /ifempty HKCU "Software\PC-BASIC"
146+
DeleteRegKey HKCU "Software\PC-BASIC"
147+
; DeleteRegKey /ifempty HKCU "Software\PC-BASIC"
164148
SectionEnd
165149

166150

167151
Function UN.onInit
152+
!insertmacro MULTIUSER_UNINIT
153+
168154
;begin uninstall, could be added on top of uninstall section instead
169155
!insertmacro UNINSTALL.LOG_BEGIN_UNINSTALL
170156
FunctionEnd

0 commit comments

Comments
 (0)