Search code examples
windowsinno-setup

How to use a preprocessor variable within a preprocessor function with Inno Setup


I try to run a PowerShell script using Exec() preprocessor function, but I need to pass two arguments to it. How can I do that? The following snippet doesn't work.

#define PSScript  SourcePath + "\\UpdateJson.ps1"
#define ConfigPath  SourcePath + "\\ClientConfig.json"
#expr Exec("PowerShell -NoProfile -ExecutionPolicy Bypass -File {#PSScript} {#ConfigPath} Str({#BuildNumber})")

Thanks!


Solution

  • Use + operator, the same way you are already using it in your PSScript and ConfigPath declarations.

    Additionally, the Exec function needs the arguments separately.

    *Other things:

    1. You should wrap the paths to double-quotes, in case they contain spaces.
    2. By default, Inno Setup preprocessor does not need escaping of backslashes.*
    #define PSScript  SourcePath + "\UpdateJson.ps1"
    #define ConfigPath  SourcePath + "\ClientConfig.json"
    
    #expr Exec("PowerShell", \
               "-NoProfile -ExecutionPolicy Bypass -File """ + PSScript + """ " + \
                   """" + ConfigPath + """ " + Str(BuildNumber))