Inno Setup: Disable components page on upgrade

前端 未结 3 601
盖世英雄少女心
盖世英雄少女心 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 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;
    

提交回复
热议问题