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 Answer
If you are using
[Run]
section then make sure you userunascurrentuser
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):
You should use
Exec()
orShellExec()
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 directivePrivilegesRequired
Valid values:
none
,poweruser
,admin
, orlowest
Use admin to ensure appropriate credentials.