2

I want to run the setup with PrivilegesRequired=lowest. How to set and run an application (dxwebsetup.exe) to install with my setup with Administrator privileges?

My code (Inno Setup - Avoid displaying filenames of sub-installers):

procedure CurStepChanged(CurStep: TSetupStep);
var
  ProgressPage: TOutputProgressWizardPage;
  ResultCode: Integer;
begin
  if CurStep = ssInstall then
  begin
    if IsComponentSelected('DirectX') then
    begin
      ProgressPage := CreateOutputProgressPage('Installing prerequsities', '');
      ProgressPage.SetText('Installing DirectX...', '');
      ProgressPage.Show;
      try
        ExtractTemporaryFile('dxwebsetup.exe');
        StartWaitingForDirectXWindow;
        Exec(ExpandConstant('{src}\_Redist\dxwebsetup.exe'), '', '', SW_SHOW,
             ewWaitUntilTerminated, ResultCode);
      finally
        StopWaitingForDirectXWindow;
        ProgressPage.Hide;
      end;
    end;
  end;
end;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Nico Z
  • 997
  • 10
  • 33

1 Answers1

2

Use ShellExec with runas verb, instead of Exec:

ShellExec('runas', ExpandConstant('{src}\_Redist\dxwebsetup.exe'), '', '', SW_SHOW,
          ewWaitUntilTerminated, ResultCode);

When the current Inno Setup process runs without Administrator privileges, you will get a UAC prompt.


It's also doable from the [Run] section:
Execute postinstall program (sub installer) with administrator privileges in Inno Setup even if the main installer does not have them

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992