Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 899
Wolfgang Reh Avatar asked Aug 30 '13 09:08

Wolfgang Reh


2 Answers

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;
like image 99
TLama Avatar answered Nov 05 '22 20:11

TLama


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.

like image 30
ygoe Avatar answered Nov 05 '22 18:11

ygoe