Search code examples
installationinno-setupelevated-privileges

Execute postinstall program (sub installer) with administrator privileges in Inno Setup even if the main installer does not have them


Just like in this question, I'm trying to implement an installer which starts another 3rd party driver installer at the end of the installation.

This is achieved by running my installer with administrative privileges (which is the default if not specified):

[Setup]
PrivilegesRequired=admin

And then using runascurrentuser at the end:

Filename: "{app}\drivers\driver.exe"; Description: "Install optional drivers"; \
    Flags: postinstall skipifsilent runascurrentuser

This works if the user has administrator privileges from the beginning.

However, I would like to allow the basic application to be installed even if the user doesn't have admin privileges. Only if the optional drivers are to be installed, should Windows pop-up the "User Account Control" window, and ask for the admin password if the user is not an admin.

Therefore I would like to start the installer without elevated privileges, and only elevate to admin if (and when) the optional diver installation is to be started.


Solution

  • If you want the [Run] entry to "run as Administrator", no matter what are the privileges of the installer, try adding runas Verb (what must be combined with shellexec flag, what in turn imply nowait, so you might want to add waituntilterminated explicitly):

    [Run]
    Filename: "{app}\drivers\driver.exe"; \
        Description: "Install optional drivers"; \
        Verb: runas; \
        Flags: postinstall skipifsilent runascurrentuser shellexec waituntilterminated
    

    It's also doable from the Pascal Script:
    Inno Setup - How to run an aplication with admin privileges if the setup is set to PrivilegesRequired=lowest?