Kryptonic
Posts: 10
Joined: Thu Oct 16, 2008 12:43 pm

.NET Install Custom Action - Rollback?

Tue Nov 11, 2008 1:18 pm

Hi all,

I have a .NET custom action that runs on the install, the success of this action is critical to the application running propperly, and if the action fails the application shouldnt be installed!

Is there anyway to do this? If an exception is handled by the code / installer can a rollback be performed?

(running Profressional version....)

Many thanks!
Will

Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact:  Website

Re: .NET Install Custom Action - Rollback?

Tue Nov 11, 2008 6:10 pm

Hi Will,

Please note that the installation will be rolled back if a custom action fails. Therefore, you can stop the installation by returning an appropriate error code. For example, you can return ERROR_INSTALL_USEREXIT if an exception is encountered.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Kryptonic
Posts: 10
Joined: Thu Oct 16, 2008 12:43 pm

Re: .NET Install Custom Action - Rollback?

Tue Nov 11, 2008 7:22 pm

Hi Cosmin

Thats great - thanks alot!

Cheers
Will

catsaremyfriends
Posts: 33
Joined: Thu Mar 26, 2009 9:21 pm

Re: .NET Install Custom Action - Rollback?

Wed Apr 08, 2009 9:12 pm

Hi Cosmin:

Could you clarify in your response how these error codes are returned?

If it is a C# .Net custom action then it will override the Install method of the Installer class. This method is of type void so it would not be a simple case of doing something like the following to report an error:

return(ERROR_INSTALL_FAILURE);

So presumably you are referring to some other mechanism?

I note that the title of the MSDN article which you referenced is "Logging of Action Return Values". Does this imply that by "logging" an error result, that the builder will pick up on this and do a rollback?

Thanks,

cats

Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact:  Website

Re: .NET Install Custom Action - Rollback?

Thu Apr 09, 2009 1:09 pm

Hi,

Please note that this cannot be done for a .NET custom action (it cannot return a different code).
I note that the title of the MSDN article which you referenced is "Logging of Action Return Values".
The title is not relevant. I mentioned the article for its content.
Does this imply that by "logging" an error result, that the builder will pick up on this and do a rollback?
After a custom action runs, depending on the custom action options Windows Installer will verify its return value. Based on this value the installation is continued or stopped in a specific way. You can find more details about this here.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

catsaremyfriends
Posts: 33
Joined: Thu Mar 26, 2009 9:21 pm

Re: .NET Install Custom Action - Rollback?

Thu Apr 09, 2009 5:41 pm

OK, I'm confused now.

Your response to Will's original question seems to indicate that this is do-able for a .Net custom action...
you can stop the installation by returning an appropriate error code
But your response to my follow up question seems to indicate that it is not...
this cannot be done for a .NET custom action (it cannot return a different code).
Could you clarify please.

Thanks,

cats

Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact:  Website

Re: .NET Install Custom Action - Rollback?

Thu Apr 09, 2009 6:02 pm

Hi,
Your response to Will's original question seems to indicate that this is do-able for a .Net custom action...
Please note that he was referring to treating an exception in the custom action code. In your case you are simply overriding the install event.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

catsaremyfriends
Posts: 33
Joined: Thu Mar 26, 2009 9:21 pm

Re: .NET Install Custom Action - Rollback?

Thu Apr 09, 2009 6:45 pm

But, Will talks about...
a .NET custom action that runs on the install
Is this not the same thing as....
simply overriding the install event

Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact:  Website

Re: .NET Install Custom Action - Rollback?

Fri Apr 10, 2009 9:10 am

Hi,

I checked with our developers and unfortunately a .NET custom action cannot return a custom value. I'm not sure why I recommended that approach to Will. If you want to return a custom value you can try using a C++ DLL.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

catsaremyfriends
Posts: 33
Joined: Thu Mar 26, 2009 9:21 pm

Re: .NET Install Custom Action - Rollback?

Thu Apr 16, 2009 8:46 pm

Would it be possible to do this indirectly by having the .NET custom action leave behind a "marker" which would be detected by a subsequent non-.NET custom action which would trigger the rollback dependent upon the marker that is left.

One way might be to have the .NET custom action create a VBS script file in the target directory if it succedes (the script would do nothing, but would execute without error). And, if the .NET custom action failed then it would not create the file.

The subsequent non-.NET custom action would then try and execute the VB script. If the script was there then the install would continue. If the script was not there then it would create an error which would trigger the rollback.

This is a pretty horrible way to accomplish this. But, would it work? Or, is there a more elegant way to accomplish the same thing?

Thanks,

cats

Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact:  Website

Re: .NET Install Custom Action - Rollback?

Tue Apr 21, 2009 11:12 am

Hi,

Yes, the approach with the file could work. You could also use a custom registry entry:
- the .NET custom action writes the registry entry if it succeeds
- another custom action reads the entry
- if the entry is not found, the second custom action returns 1602

Here you can find some sample VBScript code for reading a registry entry.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Kuz
Posts: 1
Joined: Sun Apr 26, 2009 12:04 am

Re: .NET Install Custom Action - Rollback?

Sun Apr 26, 2009 12:13 am

You could also just try throwing an InstallException from the Install override.
Throwing an InstallException should cause the installation to rollback automatically...

ie.
Throw New InstallException("Boom!")

Return to “Common Problems”