【问题标题】:Inno Setup Load defaults for custom installation settings from a file (.inf) for silent installationInno Setup 从文件 (.inf) 加载自定义安装设置的默认值以进行静默安装
【发布时间】:2016-07-27 22:10:31
【问题描述】:

我有一个安装脚本,允许用户指定他们想要安装我的应用程序的位置。它采用 [Code] 块中的 Pascal 脚本形式。

var
  SelectUsersPage: TInputOptionWizardPage;
  IsUpgrade : Boolean;
  UpgradePage: TOutputMsgWizardPage;

procedure InitializeWizard();
var
  AlreadyInstalledPath: String;
begin
  { Determine if it is an upgrade... }
  { Read from registry to know if this is a fresh install or an upgrade }
  if RegQueryStringValue(HKLM, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppId}_is1', 'Inno Setup: App Path', AlreadyInstalledPath) then
    begin
      { So, this is an upgrade set target directory as installed before }
      WizardForm.DirEdit.Text := AlreadyInstalledPath;
      { and skip SelectUsersPage }
      IsUpgrade := True;

      { Create a page to be viewed instead of Ready To Install }
      UpgradePage := CreateOutputMsgPage(wpReady,
        'Ready To Upgrade', 'Setup is now ready to upgrade {#MyAppName} on your computer.',
        'Click Upgrade to continue, or click Back if you want to review or change any settings.');
    end
  else
    begin
      IsUpgrade:= False;
    end;

  { Create a page to select between "Just Me" or "All Users" }
  SelectUsersPage := CreateInputOptionPage(wpLicense,
    'Select Users', 'For which users do you want to install the application?',
    'Select whether you want to install the library for yourself or for all users of this computer. Click next to continue.',
    True, False);

  { Add items }
  SelectUsersPage.Add('All users');
  SelectUsersPage.Add('Just me');

  { Set initial values (optional) }
  SelectUsersPage.Values[0] := False;
  SelectUsersPage.Values[1] := True;
end;

所以问题是我如何支持静默安装?当用户调用/SILENT/VERYSILENT 时,安装程​​序默认为SelectUsersPage.Values[1],即Just Me。我想通过提供答案文件来帮助支持想要更改安装目录的用户。

我没有开发所有这些代码,并且是 Pascal 的新手。

谢谢。

【问题讨论】:

    标签: inno-setup pascalscript silent-installer


    【解决方案1】:

    您可以将自定义密钥(例如 Users)添加到由 /SAVEINF 创建的 .inf 文件中。

    然后在安装程序中,查找/LOADINF command-line argument 并读取密钥并采取相应措施:

    procedure InitializeWizard();
    var
      InfFile: string;
      I: Integer;
      UsersDefault: Integer;
    begin
      ...
    
      InfFile := ExpandConstant('{param:LOADINF}');
    
      UsersDefault := 0;
    
      if InfFile <> '' then
      begin
        Log(Format('Reading INF file %s', [InfFile]));
        UsersDefault :=
          GetIniInt('Setup', 'Users', UsersDefault, 0, 0, ExpandFileName(InfFile));
        Log(Format('Read default "Users" selection %d', [UsersDefault]));
      end
        else
      begin
        Log('No INF file');
      end;
    
      SelectUsersPage.Values[UsersDefault] := True;
    end;
    

    【讨论】:

    • 谢谢!在查找 GetiniInt() 函数并看到我需要在 [Setup] 部分中创建用户键之前,我一开始并没有得到我需要在 INF 文件中存储密钥及其值的位置。我必须添加一些额外的代码来查看 IsUpgrade 是否设置为 True,因此您提供的代码块在升级期间不会执行。非常感谢您的帮助!
    猜你喜欢
    • 2020-04-21
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 2015-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多