Click here to Skip to main content
14,970,456 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello All,

I am facing problem in Windows Installer Rollback functionality using C#.net
2.0. I have created an installer class and it launches custom action
[installer type] to create database and take user inputs for application
settings, If user wants to rollback I use InstallerException with custom
message, but if I do so then in the install directory some temp files and
CreateDatabase.InstallState [CreateDatabase is the name of my application
which is launched through custom action] file are not removed and these are
supposed to be removed.
In the mentioned scenario I want to rollback in such a way that system should
be restored to its initial state as it is requirement for Windows 7 logo
certification. Any help in this regard will be highly appreciated.
Regards.
Posted

1 solution

If anything goes wrong with the install, or an uninstall occurs, you need to undo any changes you have made. In Rollback() and Uninstall() you have access to the values that were saved in stateServer. Both Rollback() and Uninstall() call my own new method RemoveCustomAdditions(). This gets the saved path strings; if they are present then the file is deleted.

public override void Rollback(IDictionary stateSaver)
{
base.Rollback(stateSaver);
RemoveCustomAdditions(stateSaver);
}
public override void Uninstall(IDictionary stateSaver)
{
base.Uninstall(stateSaver);
RemoveCustomAdditions(stateSaver);
}
private void RemoveCustomAdditions(IDictionary stateSaver)
{
try
{
string BeginLinkPath = stateSaver["BeginLinkPath"] as string;
if (!String.IsNullOrEmpty(BeginLinkPath))
File.Delete(BeginLinkPath);

string InfoLinkPath = stateSaver["InfoLinkPath"] as string;
if (!String.IsNullOrEmpty(InfoLinkPath))
File.Delete(InfoLinkPath);
}
catch (Exception ) { }
}

This code may Help you. :)
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900