In case you need to launch the application at the end of the installation in the context of the installation privileges, you can follow the below steps to implement this:
1) Create a custom action to detect if the installer process is running elevated or not
2) Launch the app based on the result search at step 1)
Create a custom action to detect if the installer process is running elevated. For example, you can create your custom action as a custom action written in C# or a custom action written in C++.
Then you can go in the Custom Actions page and add a predefined Call function from attached native DLL custom action. Using this type of custom action you can call a function from a native DLL. The target DLL will be embedded in the MSI file but will not be deployed at install time with the other application files. For details, please check the How to integrate and debug custom actions? article which may be useful to you.
Of course, you can use the VBScript or a PowerShell custom action to implement this functionality.
For example, I'm using the following powershell script to achieve this functionality:
IF the a result is True, the user has admin privileges.
Code: Select all
$user = [Security.Principal.WindowsIdentity]::GetCurrent(); (New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
The custom action needs to be executed during the Wizard Dialogs as an immediate custom action.
Note that the custom action is setting the IS_RUNNING_ELEVATED property with the search result, true or false.
2) Launch the application based on the search result.
For this, we can add 2 launch file custom actions that will be used to launch the app, conditionally. One of the custom action will have the Run as admin flag enabled:
To execute the custom actions, select the FinishDlg from the ExitDialog and using the published event tab select the related custom actions. For details how to execute a custom action on a push button, please check the following How to execute a custom action when a button is pushed article.
Also, you can place a checkbox so that the user can decide if wants to launch the application or not. Since we are not using the default mechanism to launch the app at the end of the installation sequence, we cannot use the default checkbox to condition the custom action execution, if the user agree to launch the app or not.
The ExitDialog is also added when the user runs the app in maintenance mode and decide to uninstall it. Since the checkbox only make sense during installation, use the related control conditions to hide or show it.
The last step is to execute the custom actions if the checkbox is selected. Also, if the process is running elevated or not, the corresponding custom action should be executed.
The Finish control should look something like this:
The sample project is attached to this thread, so if you are interested to take a look directly at my project, you are more than welcome to download the ZIP file.