Skip to content

Commit 11e6fe8

Browse files
committed
NSIS: support admin vs per-user installs
Update installer.nsi to avoid unnecessary UAC prompts and correctly handle admin vs standard-user installs. RequestExecutionLevel is set to "highest" and install/uninstall logic now detects account type to choose SetShellVarContext and to write Add/Remove Programs entries to HKLM (admin) or HKCU (per-user). Removed unnecessary icacls calls and ensure the uninstall registry key includes DisplayIcon/InstallLocation and NoModify/NoRepair values. Uninstaller now removes the entry from the same hive it was written to. Added robust previous-install detection across HKLM native, HKLM WOW6432Node and HKCU, and fixed file-size calculation by replacing FileSeek with a System/GetFileAttributesEx-based FileSizeNew to handle files >2GB. Also corrected the disk-space section to use the SEC_SPACE constant.
1 parent 5f3037b commit 11e6fe8

1 file changed

Lines changed: 94 additions & 40 deletions

File tree

win-installer/installer.nsi

Lines changed: 94 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
!include LogicLib.nsh
77

88
!define MUI_ICON "..\core\apps\ame\src\assets\img\ico\aspect-model-editor-targetsize-192.ico"
9+
910
;--------------------------------
1011
;General
1112

@@ -15,6 +16,11 @@
1516

1617
OutFile "aspect-model-editor-v${VERSION}-win.exe"
1718

19+
; "highest" requests the highest level the current user already has.
20+
; Admins get elevated (UAC prompt), standard users do not.
21+
; This avoids forcing a UAC prompt for a per-user install into $LOCALAPPDATA.
22+
RequestExecutionLevel highest
23+
1824
;Default installation folder
1925
InstallDir "$LOCALAPPDATA\ASPECT-MODEL-EDITOR"
2026
!define MUI_CUSTOMFUNCTION_GUIINIT GuiInit
@@ -50,13 +56,21 @@
5056
;Installer Sections
5157

5258
Section "Install"
53-
; Sets the context of $SMPROGRAMS and other shell folders.
54-
; If set to 'current' (the default), the current user's shell folders are used.
55-
; If set to 'all', the 'all users' shell folder is used.
56-
SetShellVarContext all
59+
; Use 'all' shell folders (All Users Start Menu etc.) only when running as admin.
60+
; Standard users fall back to 'current' (per-user Start Menu / Desktop).
61+
UserInfo::GetAccountType
62+
Pop $1
63+
${If} $1 == "Admin"
64+
SetShellVarContext all
65+
${Else}
66+
SetShellVarContext current
67+
${EndIf}
68+
5769
SetOutPath "$INSTDIR"
5870

59-
ExecWait 'icacls "$INSTDIR" /grant *S-1-5-19:(OI)(CI)F /T'
71+
; $LOCALAPPDATA is already fully owned by the current user — no icacls needed.
72+
; For admin installs the directory may differ; icacls is only required when
73+
; installing to a shared location (e.g. $PROGRAMFILES), which is not the case here.
6074

6175
Call uninstall_Previous_Version
6276
Call install_AME
@@ -67,41 +81,70 @@ Section "Install"
6781
;Create uninstaller
6882
WriteUninstaller "$INSTDIR\Uninstall.exe"
6983

70-
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ASPECT-MODEL-EDITOR" \
71-
"DisplayName" "Aspect Model Editor"
72-
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ASPECT-MODEL-EDITOR" \
73-
"Publisher" "eclipse.org"
74-
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ASPECT-MODEL-EDITOR" \
75-
"DisplayVersion" "${VERSION}"
76-
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ASPECT-MODEL-EDITOR" \
77-
"UninstallString" "$INSTDIR\uninstall.exe"
84+
; Write Add/Remove Programs entry -- use HKLM for admins, fall back to HKCU for standard users
85+
!define UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\ASPECT-MODEL-EDITOR"
86+
UserInfo::GetAccountType
87+
Pop $1
88+
${If} $1 == "Admin"
89+
WriteRegStr HKLM "${UNINST_KEY}" "DisplayName" "Aspect Model Editor"
90+
WriteRegStr HKLM "${UNINST_KEY}" "Publisher" "eclipse.org"
91+
WriteRegStr HKLM "${UNINST_KEY}" "DisplayVersion" "${VERSION}"
92+
WriteRegStr HKLM "${UNINST_KEY}" "UninstallString" "$INSTDIR\Uninstall.exe"
93+
WriteRegStr HKLM "${UNINST_KEY}" "DisplayIcon" "$INSTDIR\Aspect-Model-Editor.exe"
94+
WriteRegStr HKLM "${UNINST_KEY}" "InstallLocation" "$INSTDIR"
95+
WriteRegDWORD HKLM "${UNINST_KEY}" "NoModify" 1
96+
WriteRegDWORD HKLM "${UNINST_KEY}" "NoRepair" 1
97+
${Else}
98+
WriteRegStr HKCU "${UNINST_KEY}" "DisplayName" "Aspect Model Editor"
99+
WriteRegStr HKCU "${UNINST_KEY}" "Publisher" "eclipse.org"
100+
WriteRegStr HKCU "${UNINST_KEY}" "DisplayVersion" "${VERSION}"
101+
WriteRegStr HKCU "${UNINST_KEY}" "UninstallString" "$INSTDIR\Uninstall.exe"
102+
WriteRegStr HKCU "${UNINST_KEY}" "DisplayIcon" "$INSTDIR\Aspect-Model-Editor.exe"
103+
WriteRegStr HKCU "${UNINST_KEY}" "InstallLocation" "$INSTDIR"
104+
WriteRegDWORD HKCU "${UNINST_KEY}" "NoModify" 1
105+
WriteRegDWORD HKCU "${UNINST_KEY}" "NoRepair" 1
106+
${EndIf}
78107

79108
SectionEnd
80109

81110
;--------------------------------
82111
;Uninstaller Section
83112

84113
Section "Uninstall"
85-
; Sets the context of $SMPROGRAMS and other shell folders.
86-
; If set to 'current' (the default), the current user's shell folders are used.
87-
; If set to 'all', the 'all users' shell folder is used.
88-
SetShellVarContext all
114+
; Mirror the same shell context used during install so shortcuts are found
115+
; and deleted from the correct location (All Users vs. current user).
116+
UserInfo::GetAccountType
117+
Pop $1
118+
${If} $1 == "Admin"
119+
SetShellVarContext all
120+
${Else}
121+
SetShellVarContext current
122+
${EndIf}
123+
89124
ExecWait "TaskKill /IM Aspect-Model-Editor.exe /F"
90125

91126
Call un.install_AME
92127

93128
Delete "$INSTDIR\Uninstall.exe"
94129

130+
; Remove Add/Remove Programs entry from the same hive it was written to
131+
UserInfo::GetAccountType
132+
Pop $1
133+
${If} $1 == "Admin"
134+
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ASPECT-MODEL-EDITOR"
135+
${Else}
136+
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\ASPECT-MODEL-EDITOR"
137+
${EndIf}
95138
DeleteRegKey /ifempty HKCU "Software\ASPECT-MODEL-EDITOR"
96-
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ASPECT-MODEL-EDITOR"
97139
SectionEnd
98140

99141
;--------------------------------
100-
Section "" SpaceRequired
142+
; Hidden section used only for disk space calculation in GuiInit
143+
Section "-SpaceRequired" SEC_SPACE
101144
SectionEnd
102145

103146
;--------------------------------
104-
;Function
147+
;Functions
105148

106149
Function DirectoryLeave
107150
ExpandEnvStrings $0 "%USERPROFILE%\ASPECT-MODEL-EDITOR"
@@ -130,36 +173,47 @@ Function un.install_AME
130173

131174
Delete "$SMPROGRAMS\ESMF\Aspect-Model-Editor.lnk"
132175
Delete "$SMPROGRAMS\ESMF\Aspect-Model-Editor Uninstaller.lnk"
133-
RMDir /r "$SMPROGRAMS\ESMF"
176+
RMDir /r "$SMPROGRAMS\ESMF"
134177

135178
Delete "$DESKTOP\Aspect-Model-Editor.lnk"
136179
FunctionEnd
137180

138-
;WOW6432Node automatically added by windows for 64 bits applications
181+
; Check all three possible registry locations for a previous installation:
182+
; 1. HKLM native 64-bit (installed by admin)
183+
; 2. HKLM WOW6432Node 32-bit (installed by admin on 64-bit OS, legacy)
184+
; 3. HKCU (installed by standard user)
139185
Function uninstall_Previous_Version
140-
; Check for uninstaller.
141-
ReadRegStr $R0 HKLM "SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ASPECT-MODEL-EDITOR" "UninstallString"
186+
ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ASPECT-MODEL-EDITOR" "UninstallString"
187+
${If} $R0 == ""
188+
ReadRegStr $R0 HKLM "SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ASPECT-MODEL-EDITOR" "UninstallString"
189+
${EndIf}
190+
${If} $R0 == ""
191+
ReadRegStr $R0 HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ASPECT-MODEL-EDITOR" "UninstallString"
192+
${EndIf}
142193

143194
${If} $R0 != ""
144-
ExecWait '"$R0" /S'
145-
Sleep 10000
195+
ExecWait '"$R0" /S'
196+
Sleep 10000
146197
${EndIf}
147198
FunctionEnd
148199

149-
Function GuiInit
150-
Push "$INSTDIR\Aspect-Model-Editor.exe"
151-
Call FileSizeNew
152-
Pop $0
153-
IntOp $0 $0 / 1024
154-
SectionSetSize ${SpaceRequired} "$0"
200+
; FIX: Use GetFileSize (System plugin) instead of FileSeek to correctly handle files larger than 2 GB
201+
Function FileSizeNew
202+
Exch $0
203+
Push $1
204+
Push $2
205+
System::Call "kernel32::GetFileAttributesEx(t '$0', i 0, @r1)"
206+
System::Call "*$1(i, l, l, l, l .r2, l)"
207+
IntOp $0 $2 / 1024
208+
Pop $2
209+
Pop $1
210+
Exch $0
155211
FunctionEnd
156212

157-
Function FileSizeNew
158-
Exch $0
159-
Push $1
160-
FileOpen $1 $0 "r"
161-
FileSeek $1 0 END $0
162-
FileClose $1
163-
Pop $1
164-
Exch $0
213+
; FIX: Use correct section index constant ${SEC_SPACE} instead of ${SpaceRequired}
214+
Function GuiInit
215+
Push "$INSTDIR\Aspect-Model-Editor.exe"
216+
Call FileSizeNew
217+
Pop $0
218+
SectionSetSize ${SEC_SPACE} $0
165219
FunctionEnd

0 commit comments

Comments
 (0)