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

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

    With InnoSetup 5.5.5 (and perhaps other versions), just pass whatever you want as a parameter, prefixed by a /

    c:\> myAppInstaller.exe /foo=wiggle
    

    and in your myApp.iss:

    [Setup]
    AppName = {param:foo|waggle}
    

    The |waggle provides a default value if no parameter matches. Inno setup is not case sensitive. This is a particularly nice way to handle command line options: They just spring into existence. I wish there was as slick a way to let users know what command line parameters the installer cares about.

    BTW, this makes both @knguyen's and @steve-dunn's answers somewhat redundant. The utility functions do exactly what the built-in {param: } syntax does.

    0 讨论(0)
  • 2020-12-02 16:24

    In response to:

    "With InnoSetup 5.5.5 (and perhaps other versions), just pass whatever you want as a parameter, prefixed by a /" "@NickG, yes, every constant you can expand by the ExpandConstant function"

    • This is not the case. Trying to use a command line parameter in ExpandConstant in InnoSetup 5.5.6 results in a runtime error.

    PS: I would have added a comment directly but apparently I dont have enough "reputation"

    0 讨论(0)
  • 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;
    
    0 讨论(0)
  • 2020-12-02 16:29

    Further to @DanLocks' answer, the {param:ParamName|DefaultValue} constant is documented near the bottom of the Constants page:

    http://www.jrsoftware.org/ishelp/index.php?topic=consts

    I found it quite handy for optionally suppressing the license page. Here is all I needed to add (using Inno Setup 5.5.6(a)):

    [code]
    { If there is a command-line parameter "skiplicense=true", don't display license page }
    function ShouldSkipPage(PageID: Integer): Boolean;
    begin
      Result := False
      if PageId = wpLicense then
        if ExpandConstant('{param:skiplicense|false}') = 'true' then
          Result := True;
    end;
    
    0 讨论(0)
提交回复
热议问题