InnoSetup: Getting AppName in [Code] section

Brian Campbell picture Brian Campbell · Dec 18, 2009 · Viewed 16.3k times · Source

I'm creating an installer using InnoSetup, and writing some custom handlers in a [Code] section. In one of the handlers, I would like to be able to retrieve the value of the AppName (or, potentially, the value of other parameters) defined in the [Setup] section. Is there a way for me to do this? I've looked though the documentation, but I haven't found anything that would allow me to do this. Our InnoSetup files are actually generated by our build process, which stitches together fragments that are common between all of our programs and that are program specific, so it would be inconvenient to have to define constants in the code for each program. Is there any convenient way to do this?

I'm looking for something like

MyString := ExpandConstant('{AppName}');

Except {AppName} is not a defined constant. Is there some way to query for parameters defined in the [Setup] section?

Answer

Brian Campbell picture Brian Campbell · Dec 18, 2009

Inspired by Craig's answer, I was looking at the Inno Setup Preprocessor documentation (in ISTool, not available online as far as I've found), and came across the SetupSetting function in the preprocessor.

It can be used as so:

MyString := '{#SetupSetting("AppName")}';

And as long as the [Setup] section appears before the place where this is used (ISPP seems to be only one pass), and includes a definition for AppName, this will give the results I want, without having to define an extra macro for each setting we want to extract.