InnoSetup:升级时禁用组件页面

时间:2013-08-30 09:23:44

标签: installer inno-setup

有没有办法禁用升级组件页面?我想启用我的软件升级,但我不想让用户在升级的情况下更改组件的选择。 而是安装程序,您可以从第一次安装升级所有现有组件。

我担心用户在升级过程中选择较少的组件,那些丢失的组件将作为旧版本保持安装,并且你会弄得一团糟。

我在脚本中添加了以下内容:

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

我只需要一种方法来禁用组件页面并使用先前安装(完全安装)的选择进行升级。这可能吗?

更新

[Setup]
UsePreviousTasks=true

UsePreviousTasks正在读取注册表中的现有部分,这很好。现在我需要找到隐藏选择窗口的方法。

谢谢, 沃尔夫冈

3 个答案:

答案 0 :(得分:8)

要向用户隐藏页面,请使用ShouldSkipPage事件方法。如果在此方法中返回True,则不会向用户显示该页面。如果为False,页面将通常显示。以下是如何检查安装是否为升级的示例,如果是,请跳过“选择组件”向导页面:

[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;

您提到的另一个选项可能是禁用页面的所有控件。下一个脚本显示为上一个脚本如何检查安装是否为升级,如果是,则禁用“选择组件”向导页面上的所有控件:

[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;

答案 1 :(得分:0)

类似的东西:

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;

答案 2 :(得分:0)

TLama的答案中提到的IsUpgrade函数有一个错误。如果AppId以“{”开头,必须加倍,则不会解决此问题,并且找不到它们的注册表项。这是一个适合我的纠正功能:

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;

为此函数留出单独的const,它不适用于额外的函数调用。

除此之外,64位系统似乎不会引起任何问题。如果InnoSetup以32位模式运行,则注册表虚拟化已生效,并且已将您重定向到正确的密钥。