Inno Setup - How to run an aplication with admin privileges if the setup is set to PrivilegesRequired=lowest?

萝らか妹 提交于 2021-02-07 10:18:01

问题


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;

回答1:


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.



来源:https://stackoverflow.com/questions/44566747/inno-setup-how-to-run-an-aplication-with-admin-privileges-if-the-setup-is-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!