trofimich
Posts: 3
Joined: Mon Dec 03, 2012 5:57 pm

Cancel installation from custom action (.NET application)

Hi!
Can anybody help me.
I have special application (configurator.exe) for configuring our product. Application developed on C#.
My application should detect if it were started during installation or manyally by user.

I've implemented such code for this (which worked fine in VS setup project):

Code: Select all

	[RunInstaller(true)]
	public partial class StudioInstaller : Installer
	{
		#region · Constructors and destructors ·

		public StudioInstaller()
		{
			InitializeComponent();
		}

		#endregion

		#region · Protected methods ·

		public override void Install(IDictionary stateSaver)			
                        Globals.ProgramRunningMode = ProgramRunningMode.Installation;

			bool exceptionOccured = false;
			bool canceledByUser = false;

			try
			{
//				...

				if (exceptionOccured)
				{
					if (canceledByUser)
						throw new InstallException("Canceled by user");
					else
						throw new InstallException("Error occured");
				}

				base.Install(stateSaver);
			}
			catch (Exception ex)
			{
				throw new InstallException(ex.Message);
			}
The problem is that i can't cancel installation in any case. Installation always complete succesfully.

I've also tried to write something like this:

Code: Select all

				if (exceptionOccured)
					Application.Current.Shutdown(2000);
It has no effect.

Can somebody help me?
trofimich
Posts: 3
Joined: Mon Dec 03, 2012 5:57 pm

Re: Cancel installation from custom action (.NET application

Sorry, the question is incorrect. I've thought that AdvancedInstaller will automatically recognuze my exe as .NET assembly and will call installer class.

Now i know that i should manually create .NET custom action for use installer class, otherwise assembly will be used as common executable.

We using .NET 4.5 in our codes.

Now i have 2 problems:

1) In case if my configurator called as standard system action the installation can't be cancelled using non-zero exit code.
I've tried to use Application.Current.Shutdown(1) and it has no effect. Installation always completes successfully.

2) In case if my configurator called from .NET custom action i've got en error instead of my configurator showing:
Error 1001: Could not load file or assembly 'Ostsoft.Common.dll' or one of its dependants. The system cannot find the file specified.
Ostsoft.Common.dll is our portable library which also installed with this installation.

Any ideas?
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Cancel installation from custom action (.NET application

Hello and welcome to Advanced Installer forums,

Thank you for your interest in Advanced Installer.
1) In case if my configurator called as standard system action the installation can't be cancelled using non-zero exit code.
I've tried to use Application.Current.Shutdown(1) and it has no effect. Installation always completes successfully.
Please keep in mind that in order to stop the installation process your custom action should return a return value different from 0. Also, you should enable the "Synchronous execution, check return code" execution properties from "Custom Action Properties" right pane. Please take a look on "Custom Action Return Values" article.
2) In case if my configurator called from .NET custom action i've got en error instead of my configurator showing:
Error 1001: Could not load file or assembly 'Ostsoft.Common.dll' or one of its dependants. The system cannot find the file specified.
Ostsoft.Common.dll is our portable library which also installed with this installation.
This may happens if the related custom action is launched before its resource files are deployed on target machine at installation time. So, the related custom action should be scheduled after "Install Execution Stage -> Add Resources" action group and should run as deferred.

Also, please keep in mind that a .Net Installer Class action cannot set up an installation behavior. You can try to use a DTF custom action in order to achieve what you want. Please take a look on our "Create fully fledged C# custom actions" and "How do I debug a .Net Installer Custom Action?" articles.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
trofimich
Posts: 3
Joined: Mon Dec 03, 2012 5:57 pm

Re: Cancel installation from custom action (.NET application

Please keep in mind that in order to stop the installation process your custom action should return a return value different from 0. Also, you should enable the "Synchronous execution, check return code" execution properties from "Custom Action Properties" right pane. Please take a look on "Custom Action Return Values" article.
Application.Current.Shutdown(1) do this.

http://msdn.microsoft.com/en-us/library/ms597014.aspx

This does not work.
This may happens if the related custom action is launched before its resource files are deployed on target machine at installation time. So, the related custom action should be scheduled after "Install Execution Stage -> Add Resources" action group and should run as deferred.

Also, please keep in mind that a .Net Installer Class action cannot set up an installation behavior. You can try to use a DTF custom action in order to achieve what you want. Please take a look on our "Create fully fledged C# custom actions" and "How do I debug a .Net Installer Custom Action?" articles.
Here is my screenshot:

Image

This doesn't work.
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Cancel installation from custom action (.NET application

Hello,
Application.Current.Shutdown(1) do this.

http://msdn.microsoft.com/en-us/library/ms597014.aspx

This does not work.
I've tested your scenario, but I cannot reproduce the behavior. Please make sure that the "Synchronous execution, check return code" option from "Custom Action Properties" right pane is enabled.
Here is my screenshot:

Image

This doesn't work.
As I said, it is not recommended to use a .Net Installer Class custom action to control the installation behavior because its return code cannot be caught by the installation process, and therefore will always return ERROR_SUCCESS. So, if you want to control the installation behavior using a C# custom action it is recommended to create the related custom action using the DTF framework.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”