← Click here to go back to the list of articles

Getting Started - Implementing a Simple License Checking

To get started with a simple license checking exercise go through the following steps

  1. Download and install Secure License Manager

  2. Create a Windows Forms application

    Open Microsoft Visual Studio and create a simple windows forms application with one form in it for testing.

  3. Add a reference to the Secure License Manager licensing assembly (see Figure 1)

    The Secure License Manager assemblies/dlls are located at "C:\Program Files\Simple Mode Technologies\Secure License Manager\" directory path. Add a reference to the SimpleMode.SecureLicenseManager.dll located in the above directory path.

    Add Reference - Secure License Manager
    Figure 1. Add Reference dialog.

  4. Add the following items in your test form (see Figure 2)

    • A text box for entering license key (textBoxLicenseKey)
    • A button for activating license key (buttonActivate)
    • A button for deactivating license key (buttonDeactivate)

    Test form design
    Figure 2. Add Reference dialog.

  5. Prepare license validation key (see Figure 3)

    If you have not already created a license configuration, open the Secure License Manager license key generator application and create a new license configuration. Select your test license configuration and then select the "View" -> "View License Validation Key and Code" menu option. This will open the "Validation Key and Code" dialog. Copy the validation key from this dialog and use that in your code by setting the SecureLicense.ValidationKey property or by passing it into the SecureLicense(string validationKey) constructor.

    Test form design
    Figure 3. Validation key and code dialog.

  6. Apply activation and deactivation sample code (see Listing 1)

    Copy the sample code showing in Listing 1 and make sure that the name of the Form and all user interface elements on the form match. Also copy the license validation key, that you have prepared earlier, into line of code that says "Type/Copy Your Validation Key Here."

    using System;
    using System.ComponentModel;
    using System.Windows.Forms;
    
    using SimpleMode.SecureLicenseManager;
    
    namespace Example1
    {
        public partial class TestForm : Form
        {
            private const string ValidationKey = "Type/Copy Your Validation Key Here";
            
            public TestForm()
            {
                InitializeComponent();
            }
    
            private void buttonActivate_Click(object sender, EventArgs e)
            {
                SecureLicense secureLicense = new SecureLicense(ValidationKey);
    
                secureLicense.Activate(this.textBoxLicenseKey.Text.Trim());
    
                if (secureLicense.IsValid)
                {
                    MessageBox.Show("License key activation is successful.");
                }
                else
                {
                    MessageBox.Show("License key activation failed!");
                }
            }
    
            private void buttonDeactivate_Click(object sender, EventArgs e)
            {
                SecureLicense secureLicense = new SecureLicense(ValidationKey);
    
                bool activationSuccess = secureLicense.Activate(this.textBoxLicenseKey.Text.Trim());
    
                if (activationSuccess)
                {
                    bool deactivationSuccess = secureLicense.Deactivate();
    
                    if (deactivationSuccess)
                    {
                        MessageBox.Show("License key deactivation is successful.");
                    }
                    else
                    {
                        MessageBox.Show("License key deactivation failed!");
                    }
                }
                else
                {
                    MessageBox.Show("License key activation must be successful before performing deactivation test!");
                }
            }
        }
    }
    
                        
    Imports System;
    Imports System.ComponentModel
    Imports System.Windows.Forms
    
    Imports SimpleMode.SecureLicenseManager
    
    Namespace Example1
    	Public Partial Class TestForm
    		Inherits Form
    
    		Private Const ValidationKey As String = "Type/Copy Your Validation Key Here"
    
    		Public Sub New()
    			InitializeComponent()
    		End Sub
    
    		Private Sub buttonActivate_Click(sender As Object, e As EventArgs)
    			Dim secureLicense As New SecureLicense(ValidationKey)
    
    			secureLicense.Activate(Me.textBoxLicenseKey.Text.Trim())
    
    			If secureLicense.IsValid Then
    				MessageBox.Show("License key activation is successful.")
    			Else
    				MessageBox.Show("License key activation failed!")
    			End If
    		End Sub
    
    		Private Sub buttonDeactivate_Click(sender As Object, e As EventArgs)
    			Dim secureLicense As New SecureLicense(ValidationKey)
    
    			Dim activationSuccess As Boolean = secureLicense.Activate(Me.textBoxLicenseKey.Text.Trim())
    
    			If activationSuccess Then
    				Dim deactivationSuccess As Boolean = secureLicense.Deactivate()
    
    				If deactivationSuccess Then
    					MessageBox.Show("License key deactivation is successful.")
    				Else
    					MessageBox.Show("License key deactivation failed!")
    				End If
    			Else
    				MessageBox.Show("License key activation must be successful before performing deactivation test!")
    			End If
    		End Sub
    
    	End Class
    
    End Namespace
    
                        
                        

    Listing 1. Example1 - Activation and deactivation sample code

  7. Run sample code and observe output

    Run and test sample code to test a simple activation and deactivation. The sample code is designed for testing activation and deactivation of "Unlock Keys" and as a result there is no need for a license activation web service. There is also no need for saving the activated license key for this example. After running the sample application, you will see the following outputs in your test.

    Generate an "Unlock Key" license key using the Secure License Manager license key generator and copy the license key into the "License Key" text box in the example application.

    Click on the "Activate" button - Activating a license key for the first time will show the output shown in Figure 4.

    Successful activation
    Figure 4. Example1 - successful activation

    Click on the "Deactivate" button - Deactivating an already activated license will show the output shown in Figure 5.

    Successful deactivation
    Figure 5. Example1 - successful deactivation

    Activating an invalid license key or a deactivated license key will show the output shown in Figure 6.

    Failed activation
    Figure 6. Example1 - failed activation

    Deactivating a license key that was not previously activated will show the output shown in Figure 7.

    Failed activation
    Figure 7. Example1 - deactivating a license key that is not previously activated

← Click here to go back to the list of articles