Reputation: 1622
I have
RequestExecutionLevel admin
in my NSIS script.
The problem is, if Windows UAC is set to "never notify" and a normal user runs the installer, the installer attempts to proceed anyways without asking for permissions and fails with an obscure message half way through when it attempts to modify a directory user doesnt have permission to.
What I would like to do is fail fast and show a dialog right away saying "Please run as administrator".
I have tried adding the following snippit I found, but it ALWAYS fails unless the user is actually an admin (but not normal user with Admin execution level).
UserInfo::GetAccountType
pop $0
${If} $0 != "admin"
MessageBox mb_iconstop "Administrator rights required!"
SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
Quit
${EndIf}
Upvotes: 1
Views: 1354
Reputation: 101764
There is no such thing as a normal user with administrator execution level. When a non-admin wants to elevate they must use the credentials of a administrator and the new process runs as this administrator, not the user. This is called Over The Shoulder elevation...
Using UserInfo::GetAccountType is the correct solution.
Upvotes: 1