如果在安装过程中需要特权提升来运行特定的安装程序,如何强制Inno安装程序显示UAC提示?跳过安装此安装程序并不重要。我发现可以指定AfterInstall函数来测试是否需要特权提升(IsAdminLoggedOn()),但是如何显示UAC提示以特定用户身份运行此安装程序?
找到了解决方案。因此,如果需要在安装过程中以提升的特权运行特定的安装程序,则需要:
在以下Files
部分中指定安装程序:
[Files]
Source: "SomeSetup.exe"; DestDir: "{tmp}"; AfterInstall: SomeSetupAfterInstall()
在本Code
节中,您将定义SomeSetupAfterInstall()
。如果不是管理员启动的安装程序,则应在其中使用runas
动词使用来运行ShellExec
安装程序。可能是这样的:
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;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句