English 中文(简体)
InnoSetup: Getting AppName in [Code] section
原标题:

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?

最佳回答

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.

问题回答

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.





相关问题
Correct place to install demostration projects?

With the new Windows 7 restrictions (well, new to Windows Vista anyways), we can no longer install demo projects to %ProgramFilesFolder%OurApplicationdemo since restricted users will not be able to ...

.deb package conffiles problem

I am distributing one of my applications using a .deb package, but have a problem relating to one of the files. The distribution includes a database file which is constantly updated by the app, on a ...

Closing an application using WiX

In creating my WiX installer I have run into an issue when trying to close an application before installing the upgrade. Below is an example of how I am attempting to do this. <util:...

VS 2005 Setup - HKCU

I am trying to fix an existing application that uses a Visual Studio 2005 setup project. We are requiring it to work on limited user accounts for XP, our app is written in C# for .Net 2.0. It writes ...

Do I want Publish or Release Build in VB.net?

I wrote a little (like 40 lines little) Winforms application with VB.net in Visual Studio 2010. Now I ve released the code as a Google Code project. It s easy for a developer to get the source but I d ...

configsource and installer

I have an project csproj, with app.config file, and logging Ent.Library section using configsource attribute. The logging section is in ahother file Configloggingconfiguration.config. I have a ...

热门标签