![]() |
#1 |
Junior Member
Join Date: Mar 2020
Posts: 6
|
RequestExecutionLevel user or admin
Can a single Installation Context script allow install for all users (machine) or current user? eg C:\Program Files (x86) or %USERPROFILE%\AppData\Local\Programs under Win10-64bit? Would there be issues running it under other Win OSs?
|
![]() |
![]() |
![]() |
#2 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
Linking to MSI documentation is a bit strange. If you want a MSI, use WiX.
You can also use "highest". You still need a way for the user to choose; a custom page and/or command line parameter. If the userinfo plug-in says you are not admin then just install for the user. IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#3 |
Junior Member
Join Date: Mar 2020
Posts: 6
|
I must have explained something wrong, it is an NSIS app with admin access.
|
![]() |
![]() |
![]() |
#4 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
You can't use "RequestExecutionLevel admin" if you want non-admins to be able to install, use highest or user.
You should not mix HKCU with HKLM & $PROGRAMFILES. And your version check is strange. Non-admin programs should work on 2000 & XP. And even if not, you forgot about 2003. Your check should be for AtLeastVista if you are thinking about UAC. IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#5 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
PHP Code:
IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#6 |
Junior Member
Join Date: Mar 2020
Posts: 6
|
@Anders Thank you for your help but I don't understand it.
I appreciate your advice that NSIS will do both user and admin installs and there are issues that need fixing so your other advice is a bonus. The installer is in an open source project written 5 years ago and updated by a different user each year all long gone, probably linux users with little interest in Windows. The NSIS Menu is confusing and eventually I noticed the wiki Simple tutorials link (which I tweaked to make a little clearer). It clearly explains the process for compiling scripts and got me started.
|
![]() |
![]() |
![]() |
#7 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
Yes. The important parts are the init functions, the uninstaller "tag" and using ShCtx.
The github code you linked to clearly reads and writes to HKCU. The version check tries the enforce admin rights on 2000 and XP but it is flawed because: A) It forgot about NT4 and 2003 B) UAC can be turned off on Vista+ C) Users can bypass UAC and run it as non-admin Version check should ideally use AtMost/AtLeast but that script should not check the version at all, treat all versions the same. IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#8 | |
Junior Member
Join Date: Mar 2020
Posts: 6
|
Quote:
|
|
![]() |
![]() |
![]() |
#9 |
Junior Member
Join Date: Mar 2020
Posts: 6
|
|
![]() |
![]() |
![]() |
#10 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
I'll try to explain again.
RequestExecutionLevel admin+HKLM+$ProgramFiles is a set (All users/machine install). RequestExecutionLevel user+HKCU+$AppData/$LocalAppData is a set (Single user install). You should not mix and match these. To choose a set at run-time you must use ShCtx instead of HKxx and manually set $InstDir. Mixing RequestExecutionLevel admin with HKCU creates a installer that writes to the wrong HKCU when a non-admin runs your installer with "over-the-shoulder" UAC elevation. (https://docs.microsoft.com/en-us/win...ccount-control) IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#11 | |
Junior Member
Join Date: Mar 2020
Posts: 6
|
Testing uses the NSIS\Examples\Modern UI\Basc.nsi example since it was used by the original application and should be useful for others following this thread.
In summary, the key issue is the installer needs to change the registry but a user only has access to HKEY_CURRENT_USER (HKCU) and changing HKEY_LOCAL_MACHINE (HKLM) requires admin access. As noted above to choose install type at run-time: Code tested is at the bottom of this post. Test Results: Quote:
"Do you want to allow this app from an unknown publisher to make changes to your device?" N - Installer terminates, Y - Installer runs Destination: C:\Program Files (x86)\Modern UI Test Output Folder: C:\Program Files (x86)\Modern UI Test - Verified Created uninstaller: C:\Program Files (x86)\Modern UI TestUninstall.exe - Verified Registry: Computer\HKEY_USERS\S-1-5-21-293778308-4012132540-2240235571-1001\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store Uninstall removes installation as above. Comment: * No option for Admin user to just install for current user * Non-admin install not tested PHP Code:
|
|
![]() |
![]() |
![]() |
#12 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
The code as posted does not let administrators choose, it installs for everyone if admin and for a single user if not admin (code in .onInit).
Since you are using the MUI you can dump this code and use MultiUser.nsh instead if you wish, it has a selection page. Or you can make your own custom page. (I edited your code a bit since it had a major issue with the order of WriteUninstaller and FileWriteByte) IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
|
Tags |
requestexecutionlevel |
Thread Tools | Search this Thread |
Display Modes | |
|
|