1

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.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Pavel Vladov
  • 4,707
  • 3
  • 35
  • 39

2 Answers2

3

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}
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
0

I know this is not exactly what you want, but why can't you do this:

[ISPP]
#define ScriptFileName "MyAppSetup"

[Setup]
AppPublisher={#AppPublisher}
OutputBaseFilename={#ScriptFileName}Setup

Then all you need to do it edit the one reference at the top of your file.

Update

I came across this link where it states:

You can use:

#expr SetSetupSetting("OutputBaseFilename", sFileName)

However, the difficult part is automatically finding the file name. You could use the following ISPP functions to do additional compile-time tasks that can't be done by ISPP built-in functions:

Exec function: Executes an external program to do the additional functionality, and writes the result to an INI file. By default Exec waits for the process to finish.

ReadIni function: Reads the result from the INI file, and incorporates it into the script.

How do you determine the file name is up to you. Perhaps you could enumerate the windows and extract the file name from Inno Setup window title, but because you may be having multiple Inno Setup copies open, you must find a reliable way to do it. Inno adds [Compiling] to the title during compilation which makes it easier to find which copy is being used, but there could be multiple copies in compiling state. You can be absolutely sure about which copy is running your program by checking the process ID of the parent process, you can get that by using Process32First/Process32Next and checking the 32ParentProcessID for your process. Too much work, I know..

But there was another comment:

(If you're doing an automated build, though, you can set the output filename from the command line -- that might be sufficient for what you actually want.)

So have you considered using a batch file and the command line? Then you can use the benefits of batch lines with your compiling. Information is provided here about using the current file name in batch files.

I personally think that the batch file compilation is the way to go.

Community
  • 1
  • 1
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164