我想使用
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;
ShellExec
与 runas
动词一起使用,而不是 Exec
:
ShellExec('runas', ExpandConstant('{src}\_Redist\dxwebsetup.exe'), '', '', SW_SHOW,
ewWaitUntilTerminated, ResultCode);
当前 Inno Setup 进程在没有管理员权限的情况下运行时,您将收到 UAC 提示。
也可以从
[Run]
部分实现: