Announcement

Collapse
No announcement yet.

How to run the installed application as the user who started the MSI?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to run the installed application as the user who started the MSI?

    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:
    1. Start the application using the bootstrapper, making sure it was manifested "asInvoker", while the MSI itself is manifested with "requireAdministrator";

    2. 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.
    1. 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.


    2. 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.

    3. 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.


    4. 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.

    5. Go to Build > Settings > Options, and include -ext WixUtilExtension as an additional linker option for Light.exe.

    6. 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"/>
      Delete this line completely or change it to a comment:
      Code:
      <!-- Binary Id="WixCA" SourceFile="WixCA"/ -->
      If you don't remove this Binary entry from the project XML, you will get compiler errors about duplicated symbols. Now use the provided make_setup.bat and build your final MSI.


    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
    Attached Files
    Last edited by Ulrich; 01-21-2010, 12:35 PM.

  • #2
    I have implemented this as described, and my program does run when the installer exits but it is running in Administrative mode. I am using the Standard Bootstrapper to install VC Libraries and have the Vista security level set to requireAdministrator. If I change this setting to higestAvailable my program does run under the user that started the msi installer, but then the Bootstrapper fails because of the wrong permissions. Can you suggest a way to get around this problem. By the way I am using an older version of MSI Factory V2.1.2009.0

    Comment


    • #3
      This is a tricky one. The bootstrapper will need to run as administrator or the deployment of dependencies (or other actions requiring elevation) may fail, but the MSI needs to be processed as user. By default, the bootstrapper will use MSI.RunMsiExec() to process the extracted package. Perhaps it might help if you replace this action with Shell.Execute(), calling msiexec.exe and the arguments. Please let me know if this workaround helps.

      Ulrich

      Comment


      • #4
        Thank you, your answer was very helpful and my problem is now solved.

        In each of my Dependency LUA files I replaced the lines:

        local nResult = File.Run(Program, CmdArgs, "", SW_SHOWNORMAL, true);
        with the lines:
        local nResult = Shell.Execute(Program, "runas", CmdArgs, "", SW_SHOWNORMAL, true);

        So now each dependency program runs as an Administrator, and the rest of the MSI installer runs as the Invoker..

        Comment

        Working...
        X
        😀
        🥰
        🤢
        😎
        😡
        👍
        👎