Inno Setup: Disable components page on upgrade

前端 未结 3 592
盖世英雄少女心
盖世英雄少女心 2020-12-06 13:21

Is there a way to disable the Components Page for Upgrades? I would like to enable upgrades of my software but I don\'t want to allow the users to change the selection of co

相关标签:
3条回答
  • 2020-12-06 13:51

    Something like that:

    if CurPageID=wpSelectComponents then
     begin
      if ExtraOptionAvailable() then
      begin
        Wizardform.ComponentsList.Checked[6] := true;
        Wizardform.ComponentsList.ItemEnabled[6] := true;
      end else begin
        Wizardform.ComponentsList.Checked[6] := false;
        Wizardform.ComponentsList.ItemEnabled[6] := false;
      end;
    end;
    
    0 讨论(0)
  • 2020-12-06 13:56

    The IsUpgrade function mentioned in TLama's answer has a bug. If AppId starts with a "{" which must be doubled, this isn't resolved and they registry key will not be found. Here's a corrected function that works for me:

    function IsUpgrade: Boolean;
    var
        Value: string;
        UninstallKey: string;
    begin
        UninstallKey := 'Software\Microsoft\Windows\CurrentVersion\Uninstall\' +
            ExpandConstant('{#SetupSetting("AppId")}') + '_is1';
        Result := (RegQueryStringValue(HKLM, UninstallKey, 'UninstallString', Value) or
            RegQueryStringValue(HKCU, UninstallKey, 'UninstallString', Value)) and (Value <> '');
    end;
    

    Leave the separate const away for this function, it won't work with that extra function call.

    Apart from that, 64-bit systems don't seem to cause any issues. If InnoSetup runs in 32-bit mode, the registry virtualisation is in effect and redirects you to the correct key already.

    0 讨论(0)
  • 2020-12-06 14:04

    To hide a page from user use the ShouldSkipPage event method. If you return True in this method, the page won't be shown to user. If False, the page will be displayed as usually. Here 's an example of how to check if the installation is an upgrade and if so, skip the Select Components wizard page:

    [Setup]
    AppId=B75E4823-1BC9-4AC6-A645-94027A16F5A5
    AppName=My Program
    AppVersion=1.5
    DefaultDirName={pf}\My Program
    
    ; here is the place for your [Components] section and the rest of your script
    
    [Code]
    const
      UninstallKey = 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#SetupSetting("AppId")}_is1';
    
    function IsUpgrade: Boolean;
    var
      Value: string;
    begin
      Result := (RegQueryStringValue(HKLM, UninstallKey, 'UninstallString', Value) or
        RegQueryStringValue(HKCU, UninstallKey, 'UninstallString', Value)) and (Value <> '');
    end;
    
    function ShouldSkipPage(PageID: Integer): Boolean;
    begin
      Result := (PageID = wpSelectComponents) and IsUpgrade;
    end;
    

    Another option you mentioned might be to disable all the controls of the page. The next script shows as the previous one how to check if the installation is an upgrade and if so, disables all the controls on the Select Components wizard page:

    [Setup]
    AppId=B75E4823-1BC9-4AC6-A645-94027A16F5A5
    AppName=My Program
    AppVersion=1.5
    DefaultDirName={pf}\My Program
    
    ; here is the place for your [Components] section and the rest of your script
    
    [Code]
    const
      UninstallKey = 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#SetupSetting("AppId")}_is1';
    
    function IsUpgrade: Boolean;
    var
      Value: string;
    begin
      Result := (RegQueryStringValue(HKLM, UninstallKey, 'UninstallString', Value) or
        RegQueryStringValue(HKCU, UninstallKey, 'UninstallString', Value)) and (Value <> '');
    end;
    
    procedure DisablePageControls(Page: TNewNotebookPage);
    var
      I: Integer;
    begin
      Page.Enabled := False;
      for I := 0 to Page.ControlCount - 1 do
        Page.Controls[I].Enabled := False;
    end;
    
    procedure InitializeWizard;
    begin
      if IsUpgrade then
        DisablePageControls(WizardForm.SelectComponentsPage);
    end;
    
    0 讨论(0)
提交回复
热议问题