我想以非管理员模式运行安装程序。但是,当缺少某些驱动程序时,我希望安装它。由于无法从[Code]
更改指令值,因此我在考虑是否可以获取当前的执行模式,然后构建逻辑。
[Setup]
PrivilegesRequired=lowest
[Code]
function IsKvaserNotInstalled: boolean;
begin
Result := Not RegKeyExists(HKEY_LOCAL_MACHINE, 'driver path');
end;
function MyConst(): String;
begin
Result := '{#SetupSetting("PrivilegesRequired")}';
MsgBox(Result, mbInformation, MB_OK);
end;
function InitializeSetup(): Boolean;
begin
MyConst();
if IsKvaserNotInstalled() then begin
MsgBox('KVASER driver is not installed. ' +
'We require setup to run in admin mode to install it.', mbInformation, MB_OK);
Result := false;
end else
Result := true;
end;
function IsKvaserNotInstalled: boolean;
begin
result := Not RegKeyExists(HKEY_LOCAL_MACHINE,
'SOFTWARE\KVASER AB\CANDriver 1.0\Drivers\kcanv');
end;
[Run]
Filename: "{app}\drivers_setup.exe"; Parameters: "/S" ; Check: IsKvaserNotInstalled;
MyConst()
返回给定的[Setup]
部分的值。但是,我希望获取表明该exe当前正在以管理员模式运行的值。如果我得到一个不同的值,则可以将其添加到if子句中并继续设置。
这不起作用,因为我需要进行无提示安装:Inno Setup - How to run an aplication with admin privileges if the setup is set to PrivilegesRequired=lowest?
要测试安装程序是否以管理员权限运行,请使用IsAdmin
function。