Click here to Skip to main content
14,970,456 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everybody,
Am new to Windows setup project and am trying to put in custom action where in am accepting Cd key and checking it against record in DB.
What I want is if CD key is invalid it should give msg and stop the further installation process. Am using base.Rollback() in installer.cs file but still its not rolling back the installation. Am getting msg properly even the rollback() is getting called but its not actually rolling back the installation.
Can anybody help me out?

thanks in advance
Posted
Updated 24-Dec-12 2:24am
v2
Comments
CHill60 24-Dec-12 8:44am
   
Can you post the code where you reject the invalid key and your rollback for us to have a look at?
Pooja Kharape 25-Dec-12 6:56am
   
protected override void OnBeforeInstall(IDictionary savedState)
{
MessageBox.Show("OnBeforeInstall");
base.OnBeforeInstall(savedState);
error_msg = "";
try
{

string cd_key;
cd_key = Context.Parameters["PathValue"];
if (cd_key == "")
{
error_msg = "Enter Cd key to proceed further";
this.Rollback(savedState);
}
else
{
string str = "Select isnull(mac_id,'') as mac_id,cd_key,isnull(is_installed,0) as is_installed from tblInstallationMaster where cd_key='" + cd_key + "' and is_active=1";
try
{
ConnectionOpen();
}
catch (Exception ex)
{

error_msg = "You are not online. Net Connection problem";
this.Rollback(savedState);
}

if (string.IsNullOrEmpty(error_msg))
{
SqlCommand cmd = new SqlCommand(str, conn);

SqlDataReader dr = cmd.ExecuteReader();
bool has_rows = false;
string mac_id = "";
int is_installed = 1;
if (dr.HasRows)
{
dr.Read();
is_installed = int.Parse(dr["is_installed"].ToString());
mac_id = dr["mac_id"].ToString();
has_rows = true;
}
cmd = null;
ConnectionClose();
if (!has_rows)
{
error_msg = "Incorrect CD key";
this.Rollback(savedState);

}
else
{
if (string.IsNullOrEmpty(mac_id))
{

this.Install(savedState);

}
else if (mac_id == ConnectionClass.GetMACAddress())
{
// UpdateInstallationMaster();
if (is_installed == 0)
{
this.Install(savedState);

}
else
{

error_msg = "CD already Installed on your PC";
this.Rollback(savedState);

}

}
else
{
//MessageBox.Show("CD already Installed on " + mac_id);
error_msg = "CD already Installed on " + mac_id;
this.Rollback(savedState);

}
}
}
}
}
catch
{
MessageBox.Show(error_msg);
}
}
public override void Rollback(IDictionary savedState)
{ try
{
MessageBox.Show(error_msg);
base.Rollback(savedState);
}
catch
{
MessageBox.Show(error_msg);
}
}

1 solution

First, do not use the Setup project in Visual Studio. It's been removed in VS2012 and when you upgrade the project to a new Visual Studio later, it'll tell you the project type is no longer supported and you'll have lost this work.

Use a 3rd party setup creation utility, such as InstallSheild LE, InnoSetup, Advanced Installer, WiX, ...
   

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