Wixsharp: Run applic after install - ManagedProject

Created on 23 Sep 2018  路  5Comments  路  Source: oleg-shilo/wixsharp

Hi, I followed your other issue-solution (110) on how to run the installed application after installation has completed. What I am getting is it running before the installation is quite finished. Actually it runs at the moment the "Completed" dialog-view appears.

I'm using Visual Studio 2017 (15.8.5). Here is my code:

project.AfterInstall += OnAfterInstall;

`...
static void OnAfterInstall( SetupEventArgs e )
{
string path = e.InstallDir.PathCombine( "Jedit.exe" );
System.Diagnostics.Process.Start( path );
}

Method OnAfterInstall is being invoked, but while the installer is still running! Is there some other way to wire up code to happen AFTER the user has clicked on the "Finished" button?

I tried to use the sample-project 'Custom UI' (in order to hook the Finished button in the Completed dialog-window), however it won't compile because, apparently, GetEmbeddedBitmap is not defined.

Thank you for your help and all of your hard work!
James Hurst

question

Most helpful comment

I use this way of launching:
C# private readonly Id AppId = new Id("File_App_exe"); private readonly Feature Feature = new Feature(new Id("Feature_App")); ... new Project("App", new File(AppId, Feature, "App.exe"), new InstalledFileAction(AppId, "") { Id = "Start_App", Step = Step.InstallFinalize, When = When.After, Return = Return.asyncNoWait, Execute = Execute.immediate, Impersonate = true, Condition = Feature.BeingInstall(), });

All 5 comments

Hi James,

A superficial analysis of the produced WXS shows the immediate (but false) solution.

<CustomAction 
    Id="WixSharp_AfterInstall_Action" 
    BinaryKey="WixSharp_InitRuntime_Action_File" 
    DllEntry="WixSharp_AfterInstall_Action" 
    Return="check" 
    Impersonate="no" 
    Execute="deferred" />

In the code above the AfterInstall handler is set for synchronous execution so the msi waits until the action is completed. However setting Return="asyncNoWait" will not change anything at all. This is because you are already executing "Jedit.exe" asynchronously.

```C#
// synchronous
System.Diagnostics.Process.Start( path ).WaitForExit();

// asynchronous
System.Diagnostics.Process.Start( path );

```
The problem is rather a canonical "chicken-egg" problem. You cannot wait inside of the msi session routine for the session end. The only practical solution is to pas a special argument to your "Jedit.exe" to indicate that it need to wait a little or monitor the "msiexec.exe" for exit.

As for GetEmbeddedBitmap you can fix it by adding WixSharp.UI nuget package.

The corresponding defect has been raised: #480

As for GetEmbeddedBitmap you can fix it by adding WixSharp.UI nuget package.As for

Unfortunately this will not help. My mistake.
Working on it...

Done. Fixed in the latest VS extension release (v.1.6.0): https://marketplace.visualstudio.com/items?itemName=OlegShilo.WixSharpProjectTemplates

Please update the VS extension:

image

Sir oleg - you completely hooked a brothah up. Thank you!

Your new download of the samples cured the compilation-error problems.

For launching the application after the installer exits, I used this code within the application (a WPF app):

C# protected override void OnStartup( StartupEventArgs e ) { if (e.Args.Length > 0) { if (e.Args[0].Equals( "WaitForInstaller", StringComparison.OrdinalIgnoreCase )) { Process[] processes = Process.GetProcessesByName("msiexec"); for (int i = 0; i < processes.Length; i++) { var process = processes[i]; if (process.MainWindowTitle.Contains( "Jedit" )) { // Wait up to 10 seconds for the installer-process to exit. bool isExited = process.WaitForExit( 10000 ); //Console.WriteLine( "Okay then. isExited is " + isExited ); break; } } } } base.OnStartup( e ); }

I use this way of launching:
C# private readonly Id AppId = new Id("File_App_exe"); private readonly Feature Feature = new Feature(new Id("Feature_App")); ... new Project("App", new File(AppId, Feature, "App.exe"), new InstalledFileAction(AppId, "") { Id = "Start_App", Step = Step.InstallFinalize, When = When.After, Return = Return.asyncNoWait, Execute = Execute.immediate, Impersonate = true, Condition = Feature.BeingInstall(), });

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CADbloke picture CADbloke  路  4Comments

JasShao picture JasShao  路  4Comments

empz picture empz  路  3Comments

mgkeeley picture mgkeeley  路  5Comments

meytes picture meytes  路  3Comments