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

前端 未结 10 1142
梦谈多话
梦谈多话 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:18

    This is the function I wrote, which is an improvement of Steven Dunn's answer. You can use it as:

    c:\MyInstallDirectory>MyInnoSetup.exe /myParam="parameterValue"
    
    myVariable := GetCommandLineParam('/myParam');
    
    { util method, equivalent to C# string.StartsWith }
    function StartsWith(SubStr, S: String): Boolean;
    begin
      Result:= Pos(SubStr, S) = 1;
    end;
    
    { util method, equivalent to C# string.Replace }
    function StringReplace(S, oldSubString, newSubString: String): String;
    var
      stringCopy: String;
    begin
      stringCopy := S; { Prevent modification to the original string }
      StringChange(stringCopy, oldSubString, newSubString);
      Result := stringCopy;
    end;
    
    { ================================================================== }
    function GetCommandlineParam(inParamName: String): String; 
    var
       paramNameAndValue: String;
       i: Integer;
    begin
       Result := '';
    
       for i := 0 to ParamCount do
       begin
         paramNameAndValue := ParamStr(i);
         if (StartsWith(inParamName, paramNameAndValue)) then
         begin
           Result := StringReplace(paramNameAndValue, inParamName + '=', '');
           break;
         end;
       end;
    end;
    

提交回复
热议问题