Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
478 views
in Technique[技术] by (71.8m points)

pascalscript - Inno Setup Load defaults for custom installation settings from a file (.inf) for silent installation

I have a setup script that allows the user to specify where they would like to install my application. It is in the form of a Pascal script within the [Code] block.

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, 'SoftwareMicrosoftWindowsCurrentVersionUninstall{#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;

So the question is how could I support a silent installation? When a user invokes /SILENT or /VERYSILENT the installer defaults to SelectUsersPage.Values[1], which is for Just Me. I want to help support the user that wants to change the installation directory with providing an answer file.

I didn't develop all of this code, and am a newbie with Pascal.

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can add a custom key (say Users) to the .inf file created by the /SAVEINF.

Then in the installer, lookup the /LOADINF command-line argument and read the key and act accordingly:

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...