Tushar Chhabhaiya
Tushar Chhabhaiya

Reputation: 700

Custom uninstall Action c#

I have some condition, which I have to check at the time of uninstall, if conditions match then I want to stop the installation process and want to roll back the uninstall process.

Currently I am using the custom actions for the uninstalling using installer class. In which I check for condition whether match or not? if match then I have done rollback and no then the uninstallation will continue.

I have used following code in uninstall script action.

public override void Uninstall(IDictionary savedState)
        {
            if (Condition)
            {
                Rollback(savedState);
            }
            else
            {
                base.Uninstall(savedState);
            }

        }

But this code is not able to rollback the uninstall process. Let me know what is wrong with this code. if any new idea then let me know.

Upvotes: 2

Views: 1325

Answers (1)

Nikhil Agrawal
Nikhil Agrawal

Reputation: 48558

Throw an InstallException and it will rollback. Read this.

public override void Uninstall(IDictionary savedState)
{
    if (Condition)
    {
        throw new InstallException("blah blah");
        // What ever you want to do after
    }
    else
    {
        base.Uninstall(savedState);
    }               
}

Your code won't work. Why?

When rollback happens Rollback custom action is called.

Its not other way round that calling Rollback custom action will cause Rollback.

Upvotes: 2

Related Questions