How to make Inno Setup /DIR command line switch wo

2020-07-25 00:55发布

问题:

When I use /DIR command line switch

"Mysoft.exe" /VERYSILENT /installerbusiness /DIR="C:\Program Files (x86)"

The specified path does not get used for path box on my custom page :

I'm using code based on Use two/multiple selected directories from custom page in Files section.

This is an example of the code I'm using.

[Code]

var
  Install: TInputDirWizardPage;

procedure InitializeWizard();
begin
  Install :=
    CreateInputDirPage(
      wpSelectDir, CustomMessage('Readyinstall'), 
      CustomMessage('Readyinstallpc'), #13#10#13#10 + CustomMessage('Tocontinuet'),
      True, 'Mysoft');

  Install.Add(CustomMessage('DestFolder'));

  Install.Values[0] := ('C:\Program Files\Mysoft');
  { ... }
end;

回答1:

If you want the standard behavior of "installation path" of Inno Setup, which includes the processing of /DIR= command-line switch, you have to link your custom path box to the standard one.

So particularly, you have to copy the initial value of the WizardForm.DirEdit to your custom box:

var
  Page: TInputDirWizardPage;

procedure InitializeWizard();
begin
  ...
  Page := CreateInputDirPage(...);
  Page.Add(...);
  Page.Values[0] := WizardForm.DirEdit.Text;
end;

This solution handles not only /DIR=, but also /LOADINF=.

To complement the code above, you should copy the value back to WizardForm.DirEdit. This way you make sure that on re-install/upgrade, the previously selected value is reused. This is shown in point 1) of my answer to Use two/multiple selected directories from custom page in Files section.


If the above is too complicated (or not obvious) to implement, because of a complex logic of your installer, you can handle the /DIR= switch programmatically yourself. See Setting value of Inno Setup custom page field from command-line.

procedure InitializeWizard();
var
  DirSwitchValue: string;
begin
  Install := ...;

  Install.Add(...);

  DirSwitchValue := ExpandConstant('{param:DIR}');
  if DirSwitchValue <> '' then
  begin
    Install.Values[0] := DirSwitchValue;
  end
    else
  begin
    Install.Values[0] := ExpandConstant('{pf}\Mysoft');
  end;
end;

This solution obviously does not handle /LOADINF=. How to process .inf files is shown in Inno Setup Load defaults for custom installation settings from a file (.inf) for silent installation.

Also, with this solution, the previously used installation path won't be used for upgrades/re-installs. How to implement that is shown in Inno Setup with three destination folders.