Passing string value to Inno Setup from command line application

The scenario is that we have a client / server application with client installation, which is the boot machine using Inno Setup, which downloads the client from the server specified by the IP / port number. We would like to know if there is a server on the local network via UDP broadcasting, and you can write a console application that does this. The problem is how do we transfer information from the console application to the installer?

I can capture the return code, but it can only be int. As far as I can tell, the only functions for reading a file in Inno Setup are in the preprocessor, so we cannot read the file created at run time by the console application. The only thing I can think of is to return an int, where the first 4 digits are the position. and: in front of the port, and then analyze a value that seems hacky, flimsy and error prone, especially considering that I am not familiar with Inno Setup syntax / functions for constructing a string.

Any suggestions?

+2
source share
6 answers

I don’t know how to load the parameter from the command line, but you can use LoadStringFromFile to load the contents of the file or GetIniString to read the parameter from the ini file.

More generally, find the "Support Feature Reference" in the Inno Setup help file. This page will provide you with a list of all Inno features (not including the preprocessor). If you cannot find this page (if you only find information about the preprocessor), you may be looking for the wrong help file. Please note that the content of the Inno Setup Help is not that great, but the index is very good.

Command line parameters are documented on the Installation Command Line Parameters page. You might be able to trick Inno into using one of the existing options, but using an ini file seems like it would be the easiest approach.

+3
source

If you want to parse command line arguments from code in Inno Setup, use a method like this. Just call the installer from the command line as follows:

 c:\MyInstallDirectory>MyInnoSetup.exe -myParam parameterValue 

Then you can call GetCommandLineParam as follows where 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 ...

+5
source

InnoSetup includes an interpreted Pascal language that can be used in many cases during installation.

For example, I know that he can read the registry, and I am sure that he can read files, at least from some folders. The application in console mode can write a temporary file or delete one or more registry keys containing the information necessary in the rest of the installer, and which can be returned from the scripting environment to the script setting. The installer can even clear the temporary file and / or keys later.

+1
source

In the Inno Installation Guide:

{parameter: ParamName | DefaultValue}

 Embeds a command line parameter value. * ParamName specifies the name of the command line parameter to read from. * DefaultValue determines the string to embed if the specified command line parameter does not exist, or its value could not be determined. 

Example:

[Settings] AppId = ... AppName = {parameter: exe_name | hug} .exe

Read more: www downloadatoz com / manual / in / inno-setup / topic_consts.htm

0
source

The above anonymous answer should be retained.

I managed to pass an argument to my installer by simply accessing 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 
0
source

Source: https://habr.com/ru/post/974815/


All Articles