Creating a custom action to launch the application installer and exit

Thanks to StackOverflow, yesterday I learned how to add a custom action to the Visual Studio installer to run my program after the update. The problem that I am facing right now is that at the end of the installer, the program opens, but the installer never quits until I exit my application.

Is there a way to ensure that the application starts only after the user clicks on the MSI package? Or does the program begin at the finish line of the installer, but does the installation program exit and exit?

I am running Visual Studio 2010 in case that matters.

+4
source share
2 answers

After some Googling, I found out that the custom action for the Visual Studio installer might need to point to the installer class. So I created a new type class project in my solution. I deleted the class1.cs file and added the installer class to the new project with the following code (mental note: you need to use security.permissions at some point):

using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Configuration.Install; using System.Linq; using System.Diagnostics; using System.Security.Permissions; namespace AppName { [RunInstaller(true)] public partial class InstallerClass : System.Configuration.Install.Installer { public InstallerClass() { InitializeComponent(); } public override void Commit(System.Collections.IDictionary savedState) { base.Commit(savedState); System.Diagnostics.Process.Start(Context.Parameters["TARGETDIR"].ToString() + "application.exe"); // Very important! Removes all those nasty temp files. base.Dispose(); } } } 

After adding the InstallerClass, I right-click on the installer project and select Add> Project Output and added the installer class. Then I right-clicked on the installed project and did View> Custom Action. I added the installer class to the Install and Commit folders (if you just add it to Commit, you get an error 1001: the InstallState file could not be found. Due to the override of commit, it will only work when committing. Apparently, the InstallState created on stage 2, so if it is not in both, then it will fail).

You must add a CustomActionData entry. To do this, select "Initial Output from InstallerClass" and go to the "Initiatives" tab. Paste the following data into CustomActionData:

 /TARGETDIR="[TARGETDIR]\" 

After that, the application starts correctly when the installation is completed, and you can close the installation program, and not wait for the application to exit!

Just what I need. Thanks to Google for saving my bacon.

The only problem I noticed was the installation, which now creates several .tmp files and the .InstallState file in my ApplicationFolder. I am wondering if there is anything extra that needs to be added to the installer class to get rid of these useless files?

It turned out how to get rid of temporary files. Updated code using Dispose ().

+12
source

I followed the following instructions: http://msdn.microsoft.com/en-us/library/d9k65z2d.aspx

.. And I got the error "Error 1001: Could not find InstallState file".

After reading ThaKidd's answer above, I realized that I would have to: Add the installer class to the installation and commit folders.

Really important. Just leaving this here for future visitors (I would add a comment if SO allowed me ...)

+3
source

Source: https://habr.com/ru/post/1314634/


All Articles