Inno Setup custom dialog with per user or per machine installation

后端 未结 1 433
轻奢々
轻奢々 2020-12-30 15:52

I\'m using Inno Setup (http://www.jrsoftware.org/isinfo.php) to create native bundle for my JavaFX application.

I\'d like to create a custom step where ask the user

相关标签:
1条回答
  • 2020-12-30 16:30

    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;
    

    0 讨论(0)
提交回复
热议问题