The Manco Licensing System includes (optionally) Activation Web Service that allows activate licenses so that they can be used only on one PC at a time. Product activation is a technology used by a number of licensing schemes available today. Manco Licensing System allows you using product activation to fasten a license to a single computer so that the same license can’t be used on another PC.
First what you should do after installation of the Activation Web Service is setup database access.
Activation Web Service automatically sends e-Mail with activation key to user. For this purposes you should configure activation letter for every product to use with activation schema.
To set licensing schema use activation key you should add “Activation Key” field to the corresponding license type.
In your project add form that would perform product activation. Depends on what base licensing schema (License File or Unlock Key) you are using for your product this form could contain text box for Unlock Key. Add button for activation, text box for Activation Key and button to accept activation key and close form. In case of using “Unlock Key” schema those form could looks like the following:
Add Web Reference to the activation server to your product:
Add “On Click” event handler to your license activation form. This handler should pass the “Unlock Key” (if applicable) to the license object, obtain product ID and send it to the activation server. In case of using “Unlock Key” schema prospective code could looks like the following:
[C#]
private void cmdActivate_Click(object sender, System.EventArgs e)
{
// If "Unlock Key" has been entered
if(txtUnlockKey.Text.Trim() != string.Empty)
{
// Pass "Unlock Key" to the license object
m_License.UnlockKey = txtUnlockKey.Text.Trim();
// Get instance of the Activation Service
ActivationService.ActivationService loActivationService =
new ActivationService.ActivationService();
try
{
// Get product ID from the license and try to activate product
if(loActivationService.ActivateProduct(m_License.ProductID))
{
// In case when product succesfully activated user
// will recieve e-Mail with activation code.
MessageBox.Show(
"Activation Key has been succesfully generated."
+ " Check your e-Mail box for it");
}
}
catch(Exception exc)
{
MessageBox.Show("Exception during activation:\n" + exc.ToString());
}
}
else
{
MessageBox.Show("Enter Unlock Key to be able activate product");
}
}
The calling code for license activation form could looks like the following
[C#]
// Instantiate license object and assign assemblies will be validated
license = (Manco.Licensing.License)LicenseManager.Validate(typeof(MainForm), this);
license.CallingAssembly = System.Reflection.Assembly.GetCallingAssembly();
license.LicensedAssembly = System.Reflection.Assembly.GetExecutingAssembly();
// Now you can use license object to validate license you provided with your product.
// It could be unlock key or license file, in any case validation should be done by
// checking IsValid property of the license object.
// In case of the using Unlock Key with Activation license has evaluation status
// till both Unlock and Activation Keys are entered.
if(license.IsEvaluation)
{
LicenseForm loForm = new LicenseForm();
loForm.License = license;
if(loForm.ShowDialog() == DialogResult.OK
&& loForm.UnlockKey.Trim() != string.Empty
&& loForm.ActivationKey.Trim() != string.Empty)
{
license.UnlockKey = loForm.UnlockKey;
license.ActivationKey = loForm.ActivationKey;
}
}
if(!license.IsValid)
throw new Exception("Illegal use of the sample application");
Activation Web Service automatically sends e-Mail with activation key to user. So you should have at least customer e-Mail to get this schema works. All necessary information on customer should be obtained during preparing license file, generating unlock key or from separate sale service. If valid purchase information isn’t exists in the database, then Activation Web Service suppose that this is attempt of hacking and throw exception. Don’t forget enter customer’s e-Mail if you are using Product Activation Schema.
Another valuable feature of the Activation Web Service is ability to validate Activation Key through the Internet. It’s up to you to configure your application to use this feature. Your application can connect with Activation Web Service to check if the licensing information (license file or Unlock Key) and Activation Key are valid and stop execution if they aren’t. So if you remove Activation Key or information about purchase from the database your application will not work (in case of money back, for example). To allow your licensed product validate activation key through the Internet you should include to your application code that looks like the following:
[C#]
// If license isn't evaluation, then request validation on the Activation Web Service
if(!license.IsEvaluation)
{
// It seems that license has been activated already. Validate it using Activation Web Service
// Get instance of the Activation Service
ActivationService.ActivationService loActivationService = new ActivationService.ActivationService();
try
{
// Validate product ID against the Activation Key
if(!loActivationService.ValidateProduct(license.ProductID, license.ActivationKey))
{
// Activation server couldn't validate activation key against product id
throw new Exception("Illegal use of the sample application");
}
}
catch(Exception exc)
{
MessageBox.Show("Exception during activation:\n" + exc.ToString());
Application.Exit();
}
}