Normally, an installer would request administrative privileges at the beginning of the deployment procedure. Once the elevation was granted, the process is not running as the original user any longer, and if the installed application is started at the end of the setup (as shown here), files and folders may be set up using incorrect privileges.
In order to run the installed application with the same access rights as the user that originally started the MSI, we have at least two alternatives:
I will try to demonstrate the second option here, as the first is almost self-explaining. Be warned that this will need some tinkering with your installer project.
These instructions are working with the current build of MSI Factory (2.1.1009.0). Versions released afterwards may require minor adjustments to the former steps. You can find the sample project attached to this post. You can find further info in the WiX.chm help file as well, deployed in the WiX\Doc subfolder of your MSI Factory installation.
Ulrich
In order to run the installed application with the same access rights as the user that originally started the MSI, we have at least two alternatives:
- Start the application using the bootstrapper, making sure it was manifested "asInvoker", while the MSI itself is manifested with "requireAdministrator";
- We can use the WixShellExec function, present in the WixUtilExtension, impersonating the user who is installing the application.
I will try to demonstrate the second option here, as the first is almost self-explaining. Be warned that this will need some tinkering with your installer project.
- First of all, define what program should be executed after the installation. In this sample, I am going to install a program named "Demo-signed.exe". We need to define custom Property named "WixShellExecTarget", and point it to the file that should be run. Go to Project > Settings > Properties, and add a Property named WixShellExecTarget, setting the value to [#Demosigned.exe], which is the ID the component received in the project. The "#" sign will force WiX to look up the full path of the installed program.
- Now we are going to include the checkbox on the "ExitDialog" screen. In the User Interface pane on the left, click Dialogs. In Advanced mode, open the ExitDialog, and add a checkbox. As checkboxes have a gray background by default, I placed the control in the footer where it would blend in. Set the Property name of the checkbox to RUN_APPLICATION and the Value when checked to 1.
As a checkbox shows a gray background by default, I moved the control to the footer of the dialog, where it would blend in.
- We need to add the call to the Custom Action we are going to define to the "Finish" button. While still displaying the ExitDialog, double-click the Finish button to open its Properties dialog. Click the Published Events tab, and add a new event: Type Event, Event DoAction, Arguments LaunchApplication, Condition RUN_APPLICATION = 1. Then move the event to the top of the published events.
- Finally, we are going to define our Custom Action. Use the Add button to add a Call DLL action, and on the Settings tab adjust the Internal binary to WixCA, and the DLL function name to WixShellExec. On the Attributes tab, set the ID to LaunchApplication, which is the same event name we used in the former step.
Ok, what will happen? When you click the Finish button, the LaunchApplication custom action will be fired, which was defined as a call to WixShellExec. This call will look for the value of WixShellExecTarget (defined as a Property), which carries the name of the program that should be executed.
- Go to Build > Settings > Options, and include -ext WixUtilExtension as an additional linker option for Light.exe.
- Now to the final step. Go to Build > Generate WiX Files, and save the WiX XML files. Open the setup.wxs file that was generated and look for a line containing
Code:<Binary Id="WixCA" SourceFile="WixCA"/>
Code:<!-- Binary Id="WixCA" SourceFile="WixCA"/ -->
These instructions are working with the current build of MSI Factory (2.1.1009.0). Versions released afterwards may require minor adjustments to the former steps. You can find the sample project attached to this post. You can find further info in the WiX.chm help file as well, deployed in the WiX\Doc subfolder of your MSI Factory installation.
Ulrich
Comment