4

私は Inno Setup を初めて使用し、ドキュメントは既に読んでいます。これで、Inno Setup が異なる/カスタム パラメータを受け入れることができ、Pascal スクリプトを介して処理できることがわかりました。しかし問題は、Pascal での書き方がわからないことです。

コーディングに関するヘルプが得られることを願っています。

セットアップ ファイルに /NOSTART パラメーターを渡したいのですが、セットアップに「起動」のチェック マークを無効にする (チェックを外す) ように指示します。 "

ここに画像の説明を入力

または可能であれば、その起動ページは必要なく、コードを介してすべてを行います。

4

3 に答える 3

7

セクション エントリのフラグを強制的に変更することはできず、直接アクセスするのRunListは非常に厄介な回避策になるため、この 2 つのpostinstallエントリに使用しています。一方にはuncheckedフラグが指定されておらず、もう一方にはフラグが指定されています。したがって、最初のエントリはチェックされた起動チェック ボックスを表し、2 番目のエントリはチェックされていない起動チェック ボックスを表します。どちらが使用されるかは、Checkパラメーター関数によって制御されます。ここでは、コマンド ラインの末尾にパラメーターが含まれているかどうかがチェックされ/NOSTARTます。

また、特定のパラメーターがコマンド ラインの末尾に含まれているかどうかを判断するために、もう少し単純な関数を使用しました。関数を使用してCompareText、大文字と小文字を区別しない方法でテキストを比較します。CompareStr大文字と小文字を区別してパラメーター テキストを比較する場合は、関数に置き換えることができます。スクリプトは次のとおりです。

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
OutputDir=userdocs:Inno Setup Examples Output

[Run]
Filename: "calc.exe"; Description: "Launch calculator"; \
    Flags: postinstall nowait skipifsilent; Check: LaunchChecked
Filename: "calc.exe"; Description: "Launch calculator"; \
    Flags: postinstall nowait skipifsilent unchecked; Check: not LaunchChecked
[Code]
function CmdLineParamExists(const Value: string): Boolean;
var
  I: Integer;  
begin
  Result := False;
  for I := 1 to ParamCount do
    if CompareText(ParamStr(I), Value) = 0 then
    begin
      Result := True;
      Exit;
    end;
end;

function LaunchChecked: Boolean;
begin
  Result := not CmdLineParamExists('/NOSTART');
end;
于 2013-01-19T14:00:52.697 に答える
3

そして、ちょっとした調査を読んで読んで..答えを得ました。

これが私のコードです(「GetCommandLineParam」を除く)

[Code]
{
var
  StartNow: Boolean;
}

function GetCommandLineParam(inParam: String): String;
var
  LoopVar : Integer;
  BreakLoop : Boolean;
begin
  { Init the variable to known values }
  LoopVar :=0;
  Result := '';
  BreakLoop := False;

  { Loop through the passed in arry to find the parameter }
  while ( (LoopVar < ParamCount) and
          (not BreakLoop) ) do
  begin
    { Determine if the looked for parameter is the next value }
    if ( (ParamStr(LoopVar) = inParam) and
         ( (LoopVar+1) <= ParamCount )) then
    begin
      { Set the return result equal to the next command line parameter }
      Result := ParamStr(LoopVar+1);

      { Break the loop }
      BreakLoop := True;
    end;

    { Increment the loop variable }
    LoopVar := LoopVar + 1;
  end;
end;

{
function InitializeSetup(): Boolean;
var
  NOSTART_Value : String;

begin
  NOSTART_Value := GetCommandLineParam('/NOSTART');

  if(NOSTART_Value = 'false') then
    begin
      StartNow := True
    end
  else
    begin
      StartNow := False
    end;

  Result := True;
end;
}

procedure CurStepChanged(CurStep: TSetupStep);
var
  Filename: String;
  ResultCode: Integer;
  NOSTART_Value : String;
begin
  if CurStep = ssDone then
    begin
      NOSTART_Value := GetCommandLineParam('/NOSTART');
      if(NOSTART_Value = 'false') then
        begin
          Filename := ExpandConstant('{app}\{#MyAppExeName}');
          Exec(Filename, '', '', SW_SHOW, ewNoWait, Resultcode);
        end
    end;
end;

コードの更新。@TLama に感謝

function CmdLineParamExists(const Value: string): Boolean;
var
  I: Integer;  
begin
  Result := False;
  for I := 1 to ParamCount do
    if CompareText(ParamStr(I), Value) = 0 then
    begin
      Result := True;
      Break;
    end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
var
  Filename: String;
  ResultCode: Integer;
  NOSTART_Value : String;
  RunApp : Boolean;
begin
  if CurStep = ssDone then
    begin
      RunApp := CmdLineParamExists('/START');
      if(RunApp = True) then
        begin
          Filename := ExpandConstant('{app}\{#MyAppExeName}');
          Exec(Filename, '', '', SW_SHOW, ewNoWait, Resultcode);
        end

      // NOSTART_Value := GetCommandLineParam('/START');
      // if(NOSTART_Value = 'true') then
        // begin
          // Filename := ExpandConstant('{app}\{#MyAppExeName}');
          // Exec(Filename, '', '', SW_SHOW, ewNoWait, Resultcode);
        //end
    end;
end;
于 2013-01-18T07:15:38.717 に答える