inno-setup

How to get the file name of the current Inno Setup script file?


I want to obtain the name of the current Inno Setup script file in order to name the generated setup package after it. For example if the current Inno Setup script file is "MyAppSetup.iss", I want the generated setup file to be "MyAppSetup.exe".

The name of the generated setup file is controlled by the OutputBaseFilename declaration in the [Setup] section of Inno Setup, so if there's an Inno Setup preprocessor variable that returns the name of the current script file that would be great. Something like:

OutputBaseFilename={#SourceFileName}.exe

Unfortunately, there isn't an Inno Setup preprocessor variable {#SourceFileName}. I know about the {#SourcePath} variable, but it returns the directory path of the script file without it's file name. Here's a list with some predefined Inno Setup preprocessor variables, but none of them seems to return the name of the current script file. I hoped the __FILE__ variable would work after reading the descriptions of the variables in the list, but it returns an empty string.


Solution

  • It's not possible. There's the __FILE__, but it has a value for #included files only.


    If you never have more than one .iss file in a directory, you can use the FindFirst to find its name.

    #define ScriptFindHandle = FindFirst(SourcePath + "\*.iss", 0)
    #if !ScriptFindHandle
      #error "No script found"
    #endif
    #define SourceFileName = FindGetFileName(ScriptFindHandle)
    #if FindNext(ScriptFindHandle)
      #error "More than one script found"
    #endif
    #expr FindClose(ScriptFindHandle)
    #define SourceBaseName = RemoveFileExt(SourceFileName)
    

    Then to name the setup file after the current script file in the [Setup] section you should use:

    [Setup]
    OutputBaseFilename={#SourceBaseName}
    

    But if you are automating compilation of a large number of installers, I assume you use a command-line compilation. So then you can simply pass a script name in a parent batch file (or a similar script):

    set SCRIPT=MyAppSetup
    "C:\Program Files (x86)\Inno Setup 5\ISCC.exe" %SCRIPT%.iss /DBaseName=%SCRIPT%
    

    Use the BaseName like:

    [Setup]
    OutputBaseFilename={#BaseName}