Inno Setup installer has the PrivilegesRequired
directive that can be used to control, if privileges elevation is required, when installer is starting. I want my installer to work even for non-admin users (no problem about installing my app to user folder, instead of the Program Files
). So I set the PrivilegesRequired
to none
(undocumented value). This makes UAC prompt popup for admin users only, so they can install even to the Program Files
. No UAC prompt for non-admin users, so even them can install the application (to user folder).
This has some drawbacks though:
- Some people use distinct admin and non-admin accounts on their machines, working with non-admin account normally. In general, when launching installation using non-admin account, when they get UAC prompt, they enter credentials for the admin account to proceed. But this won't work with my installer, because there's no UAC prompt.
- (Overly suspicious) people with admin account, who want to install to user folder, cannot launch my installer without (not-needed) admin privileges.
Is there some way to make Inno Setup request privileges elevation only when needed (when user selects installation folder writable by admin account only)?
I assume there's no setting for this in Inno Setup. But possibly, there's a programmatic solution (Inno Setup Pascal scripting) or some kind of plugin/DLL.
There is no built-in way for conditional elevation of the setup process during its lifetime in Inno Setup. However, you can execute the setup process by using
runas
verb and kill the non-elevated one. The script that I wrote is a bit tricky, but shows a possible way how to do it.Warning:
The code used here attempts to execute the elevated setup instance always; there is no check whether the elevation is actually required or not (how to decide whether the elevation is needed optionally ask in a separate question, please). Also, I can't tell at this time, if it's safe to do such manual elevation. I'm not sure if Inno Setup doesn't (or will not) rely on the value of the
PrivilegesRequired
directive in some way. And finally, this elevation stuff should be executed only on related Windows versions. No check for this is done in this script:My solution based on @TLama's answer.
When the setup is started non-elevated, it will request elevation, with some exceptions:
If the user rejects the elevation on a new install, the installer will automatically fall back to "local application data" folder. I.e.
C:\Users\standard\AppData\Local\AppName
.Other improvements:
PrivilegesRequired=none
, the installer will write uninstall information toHKLM
, when elevated, not toHKCU
.