Conditionally running a program at the end of installation

66 views
Skip to first unread message

Joe

unread,
Oct 29, 2025, 3:41:50 PM (10 days ago) Oct 29
to innosetup
Hi,

I am writing an installation script for my application. What I need to do as part of the installation, if the user chooses to do that, is to load the license for the application. This can be done by running a command line program and passing in the correct parameters and the license file name.

However, I could not figure out how to do this using either a [Task] or [Run] entry. The command line program comes with me distribution, but I cannot call it with Exec() in my [Code] section since that program has not yet been installed in the user-selected target folder. I would also like to make this running conditional, so if the user decides not to load the license, the the task/run would not happen.

Any ideas to help me out?

Thank you!

Bill Stewart

unread,
Oct 29, 2025, 4:15:01 PM (10 days ago) Oct 29
to innosetup
There are a number of ways you could do this. One common and easy way this could be done is to create a "postinstall skipifsilent" entry in the [Run] section that appears at the end of the installation. I would recommend reading the documentation[1] as it's really quite good.


Gavin Lambert

unread,
Oct 29, 2025, 6:37:06 PM (10 days ago) Oct 29
to innosetup
On Thursday, October 30, 2025 at 8:41:50 AM UTC+13 Joe wrote:
I am writing an installation script for my application. What I need to do as part of the installation, if the user chooses to do that, is to load the license for the application. This can be done by running a command line program and passing in the correct parameters and the license file name.

However, I could not figure out how to do this using either a [Task] or [Run] entry. The command line program comes with me distribution, but I cannot call it with Exec() in my [Code] section since that program has not yet been installed in the user-selected target folder. I would also like to make this running conditional, so if the user decides not to load the license, the the task/run would not happen.

You can write [Code] that runs after the installation proper as well.  The most common place to do this is from CurStepChanged(ssPostInstall).  You can condition this code on a [Tasks] entry by calling IsTaskSelected. 

Gavin Lambert

unread,
Oct 29, 2025, 6:41:49 PM (10 days ago) Oct 29
to innosetup
On Thursday, October 30, 2025 at 8:41:50 AM UTC+13 Joe wrote:
I am writing an installation script for my application. What I need to do as part of the installation, if the user chooses to do that, is to load the license for the application. This can be done by running a command line program and passing in the correct parameters and the license file name.

Though one caveat to bear in mind with this is that if the installer is the standard PrivilegesRequired=admin type then the advice to avoid doing any per-user activities still applies here -- so if you do want to install a license at install time then it needs to be a machine-wide license and not a per-user license.  (Conversely, if the user chooses not to do this but has the option to install the license later within the app, that would of necessity be a per-user license unless your app does elevation.)

As such if you do want per-user licenses then you may be best off not doing anything at install time and just prompt the user on app startup instead.

Joe

unread,
Nov 3, 2025, 1:57:13 PM (5 days ago) Nov 3
to innosetup
Hi Bill and Gavin,

Thank you for your valuable tips. Somehow I missed that post-install Run description when perusing the help file (I am totally new to this tool, but LOVE IT!). I will try that and if I have further questions, I will come back to you.

Just a clarification: the software license for the product that I am working on will ALWAYS be installed in the HKEY_LOCAL_MACHINE branch, and the user running the installation must have chosen Admin mode when they started the installation script. If the installation is run as a regular user, my script detects that and does not prompt for the license; instead it installs the product in trial mode. So I think I am good regarding Gavin's second comment.

Thanks again for your quick responses.

joe

Joe

unread,
Nov 5, 2025, 6:45:49 AM (3 days ago) Nov 5
to innosetup
Hi again,

Thanks to your advice, I managed to create a task that is run as "postinstallation" to enter the license. My license management command line tool returns an exit code to indicate whether the operation was successful or not. However, I could not determine how to get the exit status of a task, so that I could call MsgBox to let the user know the status. Any ideas how to do this.

Also, I have seen some discussion on this forum about the installation log file. Where is that created, since I do not seem to get one?

Thank you,
joe

Joe

unread,
Nov 5, 2025, 8:14:50 AM (3 days ago) Nov 5
to innosetup
Please ignore my question about the log file. I found the information in the help file.
But still would like to know if I could get the exit code from my task.

Gavin Lambert

unread,
Nov 5, 2025, 5:11:31 PM (3 days ago) Nov 5
to innosetup
On Thursday, November 6, 2025 at 12:45:49 AM UTC+13 Joe wrote:
Thanks to your advice, I managed to create a task that is run as "postinstallation" to enter the license. My license management command line tool returns an exit code to indicate whether the operation was successful or not. However, I could not determine how to get the exit status of a task, so that I could call MsgBox to let the user know the status. Any ideas how to do this.

It's not possible to get the exit code of [Run] entries.  If you want to do something for this, you'll need to use Exec from [Code] instead.

CurStepChanged(ssPostInstall) is a place where you can Exec things after the installation proper has completed, but note that this is not directly equivalent to the postinstall [Run] entries as it happens earlier and doesn't include a checkbox. 

Another option might be to run a helper .exe that in turn launches the other tool and processes the exit code as you wish, or if possible modifying the original tool to do the equivalent.
Reply all
Reply to author
Forward
0 new messages