Wolfgang Reh
Wolfgang Reh

Reputation: 168

Inno Setup: Disable components page on upgrade

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 components in case of an upgrade. Instead the installer you upgrade all existing components from the first installation.

I am worried that it the user selects less components during the upgrade those missing components will stay installed as the old version and you get a mess.

I added the following to my script:

[Setup]
DisableDirPage=auto
DisableProgramGroupPage=auto
DirExistsWarning=auto

I just need a way to disable the components page and use the selection of the previous install (full install) for the upgrade. Is that possible?

I have found a related directive:

[Setup]
UsePreviousTasks=true

UsePreviousTasks is reading the existing section out of the registry which is good. Now I need to find a way to hide the selection window.

Thanks,
Wolfgang

Upvotes: 7

Views: 4870

Answers (3)

TLama
TLama

Reputation: 76663

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;

Upvotes: 12

ygoe
ygoe

Reputation: 20354

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.

Upvotes: 2

Weissbrot90
Weissbrot90

Reputation: 1

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;

Upvotes: 0

Related Questions