按用户或按机器安装的 Inno Setup 自定义对话框

Inno Setup custom dialog with per user or per machine installation

我正在使用 Inno Setup (http://www.jrsoftware.org/isinfo.php) 为我的 JavaFX 应用程序创建本机包。

我想创建一个自定义步骤,询问用户是否需要 "per user" 或 "per machine" 安装,以允许非特权用户和管理员安装软件。

Inno Setup 可以做到这一点吗?如果是,你能提供跟踪吗?

看看这张截图

创新设置 6

Inno Setup 6 内置了对 non-administrative install mode 的支持。

基本上,你可以简单地设置PrivilegesRequiredOverridesAllowed:

[Setup]
PrivilegesRequiredOverridesAllowed=commandline dialog


创新设置 5

在以前的 Inno Setup 版本中没有这么简单的解决方案。

最简单的方法是将 PrivilegesRequired directive 设置为 none(未记录的值):

[Setup]
PrivilegesRequired=none

这将允许非特权用户 运行 安装程序。它只会为 him/her 安装。

对于特权用户,Windows 通常会检测到可执行文件是安装程序,并且会弹出 UAC 提示。之后将为所有用户安装。

详情见Make Inno Setup installer request privileges elevation only when needed


要使安装程序安装到 "application data",当非特权用户 运行 时,您可以这样做:

[Setup]
DefaultDirName={code:GetDefaultDirName}

[Code]

function GetDefaultDirName(Param: string): string;
begin
  if IsAdminLoggedOn then
  begin
    Result := ExpandConstant('{pf}\My Program');
  end
    else
  begin
    Result := ExpandConstant('{userappdata}\My Program');
  end;
end;

如果你真的想让用户select安装到哪里(虽然我不认为真的有必要让管理员为him/her自己安装),你可以这样做这而不是上面的 DefaultDirName:

[Code]

var
  OptionPage: TInputOptionWizardPage;

procedure InitializeWizard();
begin
  OptionPage :=
    CreateInputOptionPage(
      wpWelcome,
      'Choose installation options', 'Who should this application be installed for?',
      'Please select whether you wish to make this software available for all users ' +
        'or just yourself.',
      True, False);

  OptionPage.Add('&Anyone who uses this computer');
  OptionPage.Add('&Only for me');

  if IsAdminLoggedOn then
  begin
    OptionPage.Values[0] := True;
  end
    else
  begin
    OptionPage.Values[1] := True;
    OptionPage.CheckListBox.ItemEnabled[0] := False;
  end;
end;

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  if CurPageID = OptionPage.ID then
  begin
    if OptionPage.Values[1] then
    begin
      { override the default installation to program files ({pf}) }
      WizardForm.DirEdit.Text := ExpandConstant('{userappdata}\My Program')
    end
      else
    begin
      WizardForm.DirEdit.Text := ExpandConstant('{pf}\My Program');
    end;
  end;
  Result := True;
end;