How can I force Inno Setup to show UAC prompt if elevated privileges are required to run specific installator during my setup? Skipping to install this installator is not critical. I found out that I can specify AfterInstall function to test if privilege elevation is required (IsAdminLoggedOn()), but how to show UAC prompt to run this installator as specific user?
Found the solution. So, if you need to run specific installator with elevated privileges during your setup you need:
Specify your installator in Files
section as follows:
[Files]
Source: "SomeSetup.exe"; DestDir: "{tmp}"; AfterInstall: SomeSetupAfterInstall()
In Code
section you shall define SomeSetupAfterInstall()
. There you should run your installator with runas
verb using ShellExec
if it is not admin launched setup. It might be like this:
procedure SomeSetupAfterInstall();
var
ErrorCode: Integer;
TmpPath: String;
RunMethod: String;
begin
TmpPath:=ExpandConstant('{tmp}');
if not IsAdminLoggedOn() then
begin
RunMethod := 'runas';
end else
begin
RunMethod := '';
end;
ShellExec (RunMethod, TmpPath + '\SomeSetup.exe', '', '',
SW_SHOW, ewWaitUntilTerminated, ErrorCode);
end;