Inno Setup custom dialog with per user or per machine installation

三世轮回 提交于 2019-11-30 07:38:25

Inno Setup 6

Inno Setup 6 has a built-in support for non-administrative install mode.

Basically, you can simply set PrivilegesRequiredOverridesAllowed:

[Setup]
PrivilegesRequiredOverridesAllowed=commandline dialog


Inno Setup 5

There's no such simple solution, in the previous versions of Inno Setup.

The easiest what you can do is to set PrivilegesRequired directive to none (undocumented value):

[Setup]
PrivilegesRequired=none

This will allow the installer to be run by an unprivileged user. It will install for him/her only.

For a privileged user, the Windows will typically detect that executable is an installer and it will popup a UAC prompt. It will install for all users afterwards.

For details see Make Inno Setup installer request privileges elevation only when needed


To make the installer install to "application data", when run by an unprivileged user, you can do:

[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;

If you really want the user to select, where to install to (though I do not think it is really necessary to allow the Administrator to install for him/herself), you can do this instead of the above 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;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!