Windows Develop Bookmark and Share   
 index > ClickOnce and Setup & Deployment Projects > How to programmatically cancel Uninstall Action from within Custom action
 

How to programmatically cancel Uninstall Action from within Custom action

Hello,

we have an installer project for our application for which we would like the following feature: Before the application gets uninstalled, we would like to check if certain conditions apply. Only if they do the uninstallatuin may proceed. Checking these conditions in a custom action is easy. Cancelling the uninstaller if they don't apply however is not. Is there a way to do what I would like to do?

Thanks in advance,
Tobias
TobiBo  Monday, September 21, 2009 11:09 AM

Hi TobiBo,

From my experience, these are two methods to cancel the uninstaller:

1. Call the RollBack method as follows:

public override void Uninstall(IDictionary savedState)

{

if (Check())

base.Uninstall(savedState);

else

this.Rollback(savedState);

}

2. Throw an exception.

Let me know if this helps or not.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Wednesday, September 23, 2009 3:33 AM
Hi and thanks for your reply.

1. Unfortunately calling
this.Rollback(savedState)
causes an error message "Error 1001. An exception occured while uninstalling. This exception will be ignored and the uninstall will continue. However, the application might not be fully uninstalled after the uninstall is complete. -> The savedState parameter cannot be null."

Then it shows a "Fatal error during installation.".

2. Throwing an exception also shows an error message and a fatal error.

That all does the job of preventing an uninstall but it would be nice to have that without the error messages

Any idea?

Tobias
TobiBo  Wednesday, September 23, 2009 7:12 AM

Hi TobiBo,

At first, we need to know why the savedState is null. Did you modify it before? Is the program installed successfully?

To prevent the savedState null exception, we can check it and set it to a new dictionary instance. This is a code snippet:
public override void Uninstall(IDictionary savedState)

{

if (Check())

base.Uninstall(savedState);

else

{

if (savedState == null)

{

savedState = new Dictionary<string, string>();

//Add some default values to the dictionary here.

}

//Call the rollback method.

this.Rollback(savedState);

}

}

Regards,
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Wednesday, September 23, 2009 11:25 AM
I don't know why it's null. I didn't do anything with it and yes, the programm is installed successfully.
I tried initialising the dictionary but that causes an error something like that the dictionary contains unexpected values. Is there information on what values it's supposed to have?
TobiBo  Wednesday, September 23, 2009 11:38 AM

You can use google to search for other answers

Custom Search

More Threads

• Clickonce - Change deployment URL after publish
• Upgrade issue with COM Interop using Setup project created in VS2008
• Use Publish Wizard to register (regsvr32) a dll
• configure your server to unblock any restricted file extensions
• Class not registered ??
• Setup/deployment project - conditional installation of shortcuts
• Deployment error vb .net
• Setup Problem
• Force users to update to the latest version
• Could not find part of path in Temporary Internet Files