Inno Setup自定义静默安装参数


Inno Setup 静默安装&安装无界面

Inno Setup自定义静默安装参数

// 判断传入的参数,这里设置自定义静默安装参数为"/s"
function WizardCutomSilent: Boolean;
var
 i: Integer;
begin
 Result := False;
 for i := 1 to ParamCount do
 if CompareText(ParamStr(i), '/s') = 0 then
 begin
 Result := True;
 Break;
 end;
end;

procedure InitializeWizard();
begin
  if WizardCutomSilent() = true then
  begin
      // 不显示边框,这样就能达到不会闪两下了
      WizardForm.BorderStyle:=bsNone;
  end;
end;

// 跳过页面
// The wizard calls this event function to determine whether or not a particular page (specified by PageID) should be shown at all. If you return True, the page will be skipped; if you return False, the page may be shown.
// Note: This event function isn't called for the wpPreparing, and wpInstalling pages, nor for pages that Setup has already determined should be skipped (for example, wpSelectComponents in an install containing no components).

function ShouldSkipPage(PageID:Integer):Boolean;
begin
if WizardCutomSilent() = true then
  begin
    result:=true;
  end
  else
  begin
    result:=false;
  end;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
if WizardCutomSilent() = true then
  begin
   // 因为安装过程界面隐藏不了,所以设置窗口宽高为0
    WizardForm.ClientWidth := ScaleX(0)
    WizardForm.ClientHeight := ScaleY(0)
	// 跳过Welcome页面
    if CurPageID = wpWelcome then
      WizardForm.NextButton.OnClick(WizardForm);
    if CurPageID >= wpInstalling then
        WizardForm.Visible := False
      else
        WizardForm.Visible := True;
    end;
end;