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

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

    I've modified a little bit knguyen's answer. Now it's case insensitive (you can write en console /myParam or /MYPARAM) and it can accept default value. Also I fixed the case when you receive larger parameter then expected (for ex: /myParamOther="parameterValue" in place of /myParam="parameterValue". Now myParamOther doesn't match).

    function GetCommandlineParam(inParamName: String; defaultParam: String): String; 
    var
       paramNameAndValue: String;
       i: Integer;
    begin
       Result := defaultParam;
    
       for i := 0 to ParamCount do
       begin
         paramNameAndValue := ParamStr(i);
         if  (Pos(Lowercase(inParamName)+'=', AnsiLowercase(paramNameAndValue)) = 1) then
         begin
           Result := Copy(paramNameAndValue, Length(inParamName)+2, Length(paramNameAndValue)-Length(inParamName));
           break;
         end;
       end;
    end;
    

提交回复
热议问题