问题
I have a NSIS installer/uninstaller which install an application for the current user only. There are registry writings in HKCU in order to make the application appears in control panel. It works perfectly well. However, when I try to uninstall the application from control panel, it pop-up the admin privileges pop-up box (the AUC stuff) and run the uninstaller as admin. Therefore HKCU is related to the admin account and not the user account. In this way, a user can 'uninstall' the admin application! I need to allow a user to uninstall the application without admin privileges.
I am already using !include MultiUser.nsg
et al. I've also noticed that it is possible to uninstall some random/default MS applications from control panel at user level (which doesn't require admin privileges) so I know it is possible.
回答1:
Uninstalling from the old "Programs and Features" in the classic control panel works just fine without UAC prompts. I just tested on Windows 10.0.16184 with this:
InstallDir $Temp\Test
RequestExecutionLevel user
Section
SetOutPath "$InstDir"
WriteUninstaller "$InstDir\Uninst.exe"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\NSIS_W10_HKCU_Test" "DisplayName" "NSIS W10 HKCU Test"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\NSIS_W10_HKCU_Test" "UninstallString" '"$InstDir\Uninst.exe"'
SectionEnd
Section Uninstall
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\NSIS_W10_HKCU_Test"
Delete "$InstDir\Uninst.exe"
RMDir "$InstDir"
SectionEnd
There is however a known issue if you do the same in the settings app, it will force UAC elevation even for HKCU uninstallers:
This issue in the settings app has existed for a couple of years now and I don't think Microsoft cares.
来源:https://stackoverflow.com/questions/43942181/windows-control-panel-requires-admin-privileges-when-uninstall-via-nsis