windowsinstallationinno-setupelevated-privileges

Installing application for currently logged in user from Inno Setup installer running as Administrator


A very common question about creating (Inno Setup) installers revolves around accessing/modifying a profile of a specific user (the currently logged in user) from an installer that runs with elevated/Administrator privileges.

Doing this has many drawbacks and is error prone.

All the existing answers cover part of the problem (registry, files, desktop icon, etc). A purpose of this question is to collect answers that address the problem globally, with all possible approaches.


Solution

  • Inno Setup does not have any built-in mechanism to access or modify user environment from installer running with elevated/Administrator privileges.

    All the attempts to achieve this rely on tricks like:

    Though these are not reliable, at least for these reasons:


    The only correct generic solution to this problem is to defer a setup of the user environment only to the actual user session.

    Easiest is to have the application itself do the setup on its first run.

    The installer can only deploy shared files that the application can use for the setup.

    If you cannot modify the application for whatever reason, you would have to iterate all accounts and modify them:

    If you need to make sure the settings get distributed to accounts that get created only after installation, see How to install files for each user, including future new users, in Inno Setup?


    If you are happy with a fact that the application will be setup for the logged in user only, use PrivilegesRequired=lowest:

    [Setup]
    PrivilegesRequired=lowest
    

    Then the {user*} constants will correctly refer to the current user's folder.

    If you still need Administrator privileges for some sub-task of the installation, you can requests privileges elevation for the sub-task only:

    If you want to prevent user from breaking this by explicitly running the installer with Administrator privileges, see

    Or you can programmatically find out, what is the account of the current Windows logon session:


    Another option is to allow the installer to install for the current user only:
    Make Inno Setup installer request privileges elevation only when needed