InnoSetup: Getting AppName in [Code] section

前端 未结 2 1953
我在风中等你
我在风中等你 2020-12-24 13:30

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 th

相关标签:
2条回答
  • 2020-12-24 14:14

    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.

    0 讨论(0)
  • 2020-12-24 14:23

    It's a build-time constant, not an install-time value. So you can use the Inno Setup Preprocessor add-on to define such constants. (You can install it easily via the QuickStart pack).

    Define the constant:

    #define AppName "Excellent Foo App"
    

    Use the constant in [Setup]:

    AppName={#AppName}
    

    And in Pascal code, I'm not totally sure of the syntax, but something like:

    MyString := {#AppName}
    

    Update: I realised one of my scripts uses {#emit SetupSetting("AppId")} which is easier. Brian's solution also discovered this method, and is better.

    0 讨论(0)
提交回复
热议问题