Running installed program after Install

Oct 5, 2016 at 11:18 PM
Hello Oleg,

I am having a tough time getting my installed program to run when the install is done. I am trying to get something like this done: http://wixtoolset.org/documentation/manual/v3/howtos/ui_and_localization/run_program_after_install.html

I have tried look at the samples and use a couples thing from there, like custom actions and xml injection but nothing has been working for me. I was wondering if that is possible.

Thanks,
AdamK
Oct 6, 2016 at 1:04 AM
Hi Adam,

Running the application at the end is a relatively simple task that usually doesn't require any advanced techniques as xml injection. I have captured this specific scenario in multiple samples and even created a specific one: "RunAppAtTheEnd". Why don't you try it and let me know what exactly doesn't work in your case.

Saying that, Wix# today is quite versatile and if I was you I wouldn't even bother with custom action and use ManagedSetup.AfterInstall event ('Setup Events' sample):
project.AfterInstall += project_AfterInstall;
...
static void project_AfterInstall(SetupEventArgs e)
{
    if (e.IsInstalling)
    {
        var app = System.IO.Path.Combine(e.Session.Property("INSTALLDIR"), 
                                        @"My Company\My Product\product.exe");
        Process.Start(app, "/install");
    }
}
Note that AfterInstall is already elevated so no need to worry about it.

Cheers,
Oleg
Oct 6, 2016 at 7:01 PM
Hey Oleg,

That sample did work well. The program is running but the only issue is that the user can't choose whether to run the program or not. I think I will make a Custom Dialog and see if I can do something with that.

Best Regards,
AdamK
Oct 7, 2016 at 6:50 AM
Great. If you collect user input (choice to run or not) before you start the actual install the you will need to propagate this information to the project_AfterInstall handler. There are a few ways to do that one way is to store the info in the session property then "tunnel" it into deferred AfterInstall event:
var project = new ManagedProject("My Product",
                  new Property("EXECUTEATE_THE_APP", "no"),
                  ...
project.DefaultDeferredProperties += ",EXECUTEATE_THE_APP";
...
//in cutom dialog set EXECUTEATE_THE_APP variable
...
static void project_AfterInstall(SetupEventArgs e)
{
    if (e.IsInstalling && e.session.Property("EXECUTEATE_THE_APP") != "no")
    {
        var app = System.IO.Path.Combine(e.Session.Property("INSTALLDIR"), 
                                        @"My Company\My Product\product.exe");
        Process.Start(app, "/install");
    }
}
An alternative technique is demonstrated in the 'Setup Events' sample.

Cheers,
Oleg