AX: Implementing Single User Copy Protection

See Also: OverviewImplementationPropertiesMethodsEvents

Refer to the Concept and Definitions topic Copy Protection for introductory information.

The copy protection functions of the PLUS system allow significant flexibility in controlling the illegal distribution of your applications. The following outlines the necessary source code to copy protect an application. Note that EZ Trial's Hardware Binding feature implements copy protection and may be a better alternative to this guide. Refer to Implementing EZ Trial and EZ Trigger instead.

The sample application Single User Copy Protection and License Transfer demonstrates one way to implement this form of licensing and is ready to compile and run for many programming languages. You may copy and paste this sample code into your application or use the step-by-step guide below.

One of the first steps is to determine how your application should react when an illegal copy is detected. Your application can take any of the following actions if the copy protection test fails:

Source Code Changes

  1. Add the PLUS ActiveX component to your project. See Adding PLUS ActiveX Interface to Your Applications

  2. Drop the LFile control onto your main form.

  3. Decide what type of hardware identification to use for the Computer ID Number. Refer to topic Computer ID Number for an explanation of the available algorithms. Do not use the algorithm COMPNO_NETNAME as this is reserved for network copy protection.

  4. In the FormLoad event or startup of your application, set the property CPAlgorithm and, if appropriate, CPAlgorithmDrive and/or CPAlgorithmFile. Change UseEZTrigger property to True. Choose values for TCSeed and TCRegKey2Seed and set these properties. Set the LFPassword property. Using the method below, the password will not be a text string visible in your EXE file. In Visual Basic, this looks like:

LFile1.LFPassword = "p" & "as" & "sw" & "or" & "d"

  1. Immediately after the above line, set the LFOpenFlags property to the value of 8. This tells the component to automatically create the License File if it is missing. In Visual Basic, this looks like:

LFile1.LFOpenFlags = 8

  1. Immediately after the above line, set the LFName property. The LFName property should be set to the License File in your application directory (user chosen name). In Visual Basic, this looks like:

LFile1.LFName = App.Path & "\license.ini"

  1. Add an Error event handler for LFile1, similar to what is listed below.

Private Sub LFile1_Error()

MsgBox "Error #" & LFile1.LastErrorNumber & _ 

" (" & LFile1.LastErrorString & ")" 

End 

End Sub

  1. Add a StatusChanged event handler for LFile1 to determine the mode of the application.

Private Sub LFile1_StatusChanged(ByVal startup As Boolean)

' see if we passed the copy protection test 

If LFile1.CPCheck(0) = 1 Then 

' Everything checked out 

' substitute your code here 

mnuTools.Enabled = True 

Else 

' substitute your code here 

mnuTools.Enabled = False 

MsgBox "This application must be unlocked " & _ 

"before it can be used. Please " & _ 

"contact XYZ Company for an activation code." 

End If 

End Sub

  1. Add a Trigger event handler to display a message when the user enters a valid or invalid Trigger Code.

Private Sub LFile1_Trigger(ByVal event_num As Long, _

ByVal event_data As Long) 

If event_num > 0 Then 

MsgBox "Activation Complete!" 

Else 

MsgBox "Invalid Code Entered!" 

End If 

End Sub

  1. Add a menu option to display an EZ Trigger dialog box:

Private Sub mnuUnlock_Click()

' Display our phone unlock screen. 

LFile1.ShowTriggerDlg Me.hwnd, 0, "", 0, 0 

End Sub

Set up Product Definition in LFEdit

Run LFEdit from Start / Programs / SoftwareKey Licensing System / PLUS. If using an evaluation copy, change the product name in the toolbar combo box to BasicCP. Otherwise, click Product Definition menu then Setup. Click Add to create a new definition or select an existing one and choose Properties. On the License File Tab, be sure to change the password to the same value that you used for the LFPassword property. Click on the Trigger Code tab. Be sure to change the Trigger Code seed and RegKey2Seed to the same values that you used for the TCSeed and TCRegKey2Seed properties, respectively. Click Ok to save all changes.

Run Your Application

The first time your application is executed on the client's computer, it will not have been unlocked. Therefore, it will fail the copy protection test and the "This application must be unlocked" message box will appear.

Activate the Application Using EZ Triggerâ„¢

Click on the menu option added to display the Trigger Code dialog. Write down the two numbers on the form. These two numbers are what your customer will give you by phone, fax, or e-mail. Run LFEdit. With the correct Product Definition selected in the toolbar, click on the Trigger Codes button (lock) on the toolbar. Select Code 30 and click Select. Enter the two numbers previously written down and click Generate. Write this number down. This is the unlock code that will be given to the customer. Minimize LFEdit and enter this code into the application. You should see the "Activation Complete" message appear.

More Information

You can also give Trigger Codes 27, 28, 29, 30, and 31. Trigger Code 32 is used to turn off a licensed computer. To learn about Unsupervised License Transfers using the Transfer method, refer to the sample application Single User Copy Protection and License Transfer.

Concept Link IconRelated Topics