Nekeniehl
Nekeniehl

Reputation: 1691

Launch after installation

I have an auto update application, when there is new updates, I download via ftp the installer.msi, I silent installed it and close the application, what I'm wondering is how to restart the application after the installation was successful.

I find some topics about it but nothing seems to works because different errors (bad package, error 1001, etc).

I think the approach where you add the output on the commit of the installer is the good one but I can not make it work, Any Ideas?

Thanks in advance

Upvotes: 0

Views: 318

Answers (1)

Bioukh
Bioukh

Reputation: 1968

This works for me :

[RunInstaller(true)]
public partial class Installer1 : Installer
{
    public Installer1()
    {
        InitializeComponent();
    }

    public override void Install(IDictionary savedState)
    {
        savedState.Add("InstallDir", Context.Parameters["dir"]);
        base.Install(savedState);
    }

    public override void Commit(IDictionary savedState)
    {
        base.Commit(savedState);
        Start(savedState);
    }

    private void Start(IDictionary savedState)
    {
        try
        {
            string DirPath = (string)savedState["InstallDir"];
            if (!string.IsNullOrEmpty(DirPath))
            {
                Process.Start(DirPath + @"\WindowsFormsApplication1.exe");
            }
        }
        catch
        {
        }
    }
}

You have to define /dir="[TARGETDIR]\" for CustomActionData of Install action.

Upvotes: 1

Related Questions