Search code examples
installationinno-setupelevated-privileges

Execute postinstall program with administrator privileges in Inno Setup


I'm trying to run another installer at the end of the installation (postinstall). The installer needs administrator provileges. So PrivilegesRequired=admin was added and the error still was there.

Error message below:
enter image description here

Unable to execute file:
C:\Users\User1\AppData\Local\Multi Webcam Video Recorder\webcam.exe

CreateProcess failed; code 740.
The requested operation requires elevation.

#define MyAppName "Multi Webcam Video Recorder"
#define MyAppExeName "webcam.exe"

[Setup]
AppName={#MyAppName}
PrivilegesRequired=admin

[Files]
Source: ..\src\webcam.exe; DestDir: {localappdata}\{#MyAppName}; \
    Flags: ignoreversion

[Run]
Filename: {localappdata}\{#MyAppName}\{#MyAppExeName}; \
    Description: {cm:LaunchProgram,{#MyAppName}}; \
    Flags: nowait postinstall skipifsilent

Solution

  • With postinstall flag, the program is by default executed with original privileges, even if the installer itself is running with Administrator privileges. To keep the (Administrator) privileges of the installer, add runascurrentuser flag:

    [Run]
    Filename: {localappdata}\{#MyAppName}\{#MyAppExeName}; \
        Description: {cm:LaunchProgram,{#MyAppName}}; \
        Flags: nowait postinstall skipifsilent runascurrentuser
    

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