Inno Setup Run Extracted Batch File As Administrator

batch-fileinno-setupinstallation

I am building an installer with Inno Setup and would like for the extracted files to be run as an administrator. Is there a way to force the extracted files (i.e. batch file) to run as an administrator? If so, what code elements do I need to include to perform this.

The setup log shows something like the following:

2013-05-07 17:34:25.303   -- Run entry --
2013-05-07 17:34:25.303   Run as: Current user
2013-05-07 17:34:25.303   Type: Exec
2013-05-07 17:34:25.303   Filename: C:\Temp\is-U4VID.tmp\Filename.bat
2013-05-07 17:34:25.412   Process exit code: 0

The files that I am having problems with running as an admin user are included in the [Run] section.

Best Solution

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.