Passing a string value to Inno Setup from command line app

11,808

Solution 1

Don't know how to load a parameter from the command line, but you can use LoadStringFromFile to load the contents of a file or GetIniString to read a parameter from an ini file.

More generally, look for "Support Functions Reference" in the Inno Setup Help file. This page will give you a list of all the Inno functions (not including the preprocessor). If you can't find this page (if you only find information about the preprocessor) then you may be looking in the wrong helpfile. Note that the Inno Setup Help table of contents isn't all that great but the index is very good.

Command line parameters are documented on the page "Setup Command Line Parameters". It's possible that you might be able to trick Inno by using one of the existing parameters, but using an ini file seems like it would be the most straightforward approach.

Solution 2

If you want to parse command line arguments from code in Inno Setup, then use a method similar to this. Just call the installer 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 array 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; 

Hope this helps...

Solution 3

The above anonymous answer should be upvoted.

I was able to pass an argument to my installer by just referring to the parameter by name in the script:

{param:filePath|abc}

And then when calling the installer pass the parameter value using the required format:

MyInnoSetup.exe /filePath=../foo.exe

Solution 4

InnoSetup includes an interpreted Pascal-like extension language that can be used to a lot of things during the installer's runtime.

For instance, I know it can read the registry, and I am fairly sure it can read files, at least from some folders. Your console-mode app could write a temp file or drop one or more registry keys containing the info needed in the rest of the installer, and that can be returned from the scripting environment into the setup script proper. The installer could even clean up the temp file and/or keys later.

Share:
11,808
Davy8
Author by

Davy8

Come work with me http://nerdery.com/workwithme/dv

Updated on June 05, 2022

Comments

  • Davy8
    Davy8 almost 2 years

    The scenario is that we have a client/server app with the client install being a bootstrapper using Inno Setup that downloads the client from the server specified by IP/Port number. We'd like to be able to detect if there is a server on the local network via UDP broadcasting, and can write a console app that does that. Problem is, how do we pass the information from the console app to the installer?

    I can capture the return code, but that can only be an int. As far as I can tell, the only functions to read file in Inno Setup is in the preprocessor so we can't read a file created at runtime by the console app. The only thing I can think of is to return an int where the first 4 digits are the position of the '.'s and : before the port and then parse out the value, which seems hackish, flimsy, and error prone, especially considering I'm not intimately familiar with Inno Setup syntax/functions for constructing a string.

    Any suggestions?