Is it possible to accept custom command line parameters with Inno Setup

前端 未结 10 1197
梦谈多话
梦谈多话 2020-12-02 15:33

I am preparing an installer with Inno Setup. But I\'d like to add an additional custom (none of the available parameters) command line parameters and would like to get the v

10条回答
  •  余生分开走
    2020-12-02 16:25

    If you want to parse command line arguments from code in inno, then use a method similar to this. Just call the inno script from the command line as follows:

    c:\MyInstallDirectory>MyInnoSetup.exe -myParam parameterValue
    

    Then you can call the GetCommandLineParam like this wherever you need it:

    myVariable := GetCommandLineParam('-myParam');
    
    { ================================================================== }
    { Allows for standard command line parsing assuming a key/value organization }
    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;
    

提交回复
热议问题