如何从 Inno Setup 安装程序设置为 PrivilegesRequired=lowest 来运行具有管理员权限的应用程序?

问题描述 投票:0回答:1

我想使用

PrivilegesRequired=lowest
运行设置。如何设置并运行应用程序 (dxwebsetup.exe) 以使用管理员权限安装我的设置?

我的代码(Inno Setup - 避免显示子安装程序的文件名):

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;
inno-setup pascalscript elevated-privileges
1个回答
2
投票

ShellExec
runas
动词一起使用,而不是
Exec

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

当前 Inno Setup 进程在没有管理员权限的情况下运行时,您将收到 UAC 提示。


也可以从

[Run]
部分实现:
即使主安装程序没有管理员权限,也可以在 Inno Setup 中执行安装后程序(子安装程序)

© www.soinside.com 2019 - 2024. All rights reserved.