If you are using [Run]
section then make sure you use runascurrentuser
flag (If this flag is specified, the spawned process will inherit Setup/Uninstall's user credentials (typically, full administrative privileges))
Else there are three ways how to run applications programatically (recommended way):
function Exec(const Filename, Params, WorkingDir: String; const ShowCmd: Integer; const Wait: TExecWait; var ResultCode: Integer): Boolean;
function ShellExec(const Verb, Filename, Params, WorkingDir: String; const ShowCmd: Integer; const Wait: TExecWait; var ErrorCode: Integer): Boolean;
function ShellExecAsOriginalUser(const Verb, Filename, Params, WorkingDir: String; const ShowCmd: Integer; const Wait: TExecWait; var ErrorCode: Integer): Boolean;
You should use Exec()
or ShellExec()
because they open the specified file or performs another action specified by Verb, using the same credentials as Setup/Uninstall.
But none of mentioned ways will work if your installer is not running in elevated mode.
So make sure the UAC window will appear before installer starts:
In section [Setup]
use directive PrivilegesRequired
Valid values:
none
, poweruser
, admin
, or lowest
Use admin to ensure appropriate credentials.
Best Answer
If it needs to be done at the beginning of the setup, use
Exec()
in thePrepareToInstall()
orCurStepChanged(ssInstall)
event functions. These are both after the user has said "go ahead, install" but before anything else.PrepareToInstall()
also allows you to cancel the install with a nice warning.If the file needs to be extracted from the setup first, then you can preceed it with
ExtractTemporaryFile()