AX: Implementing EZ Trial and EZ Trigger

See Also: Overview Implementation Properties Methods Events

Refer to the Concept and Definitions topics EZ Trial and EZ Trigger for introductory information. A sample application EZTrial1 is included to give an reference implementation.

The most common form of security that is implemented with PLUS is trialware - a demo that runs for a certain period of time and can be unlocked into the retail version. Using EZ Trialâ„¢ allows you to achieve these common features with the least programming effort. If the EZTrial property is set to 1 when the License File is opened, the flow chart in the EZ Trial section of Concepts & Definitions chapter is executed. The result is that your application will be in one of the following modes:

Mode

Events

0

General license error occurred; Error event fired

1

Retail application; all tests passed

2

Valid Demo; IsDemo property set to True

3

Retail application; CPCheckFailed fired

4

Expired event fired, IsExpired property set to True

5

ClockTurnedBack event fired, IsClockTurnedBack property set to True

6

Not yet implemented in ActiveX Interface

7

Not yet implemented in ActiveX Interface

Modes 1 through 5 also fire the StatusChanged event. This is the event most commonly used to determine the mode of your application and decide what action to take.

The sample application EZ Trial and EZ Trigger 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 systematic guide below.

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. In the FormLoad event or startup of your application, set the EZTrial property to 1. Change UseEZTrigger property to True and verify LFOpenFlags is 0 (the License File must be shipped with the application and cannot be created on the fly. Also, 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.EZTrial = 1

LFile1.LFOpenFlags = 0

LFile1.UseEZTrigger = True

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

  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)

If LFile1.IsExpired Or (LFile1.IsClockTurnedBack And LFile1.ExpireMode <> "N") Then

' substitute your code here 

mnuAnything.Enabled = False 

MsgBox "This demo has expired!"  

Else

mnuAnything.Enabled = True 

End If

End Sub

  1. If you want to limit functionality during the evaluation period (to encourage purchase), use code like this after the code used in the previous step:

' Demos should run with the Tools menu disabled

If LFile1.IsDemo Then

' substitute your code here 

mnuTools.Enabled = False 

MsgBox "Features are limited in demo version." 

Else

' substitute your code here 

mnuTools.Enabled = True 

End If

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

Private Sub LFile1_Trigger(ByVal event_num As Long, _

ByVal event_data As Long) 

If event_num = 0 Then 

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. 

If LFile1.ShowEZTriggerDlg(Me.hwnd, 0) = 1 Then 

MsgBox "Activation complete!" 

End If 

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 EZTrial1. Otherwise, click Product Definition menu then Setup. Click Add to create a new definition or select an existing one and choose Properties. It is important to change the Default: product name. 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. Choose values for Trigger Code seed and RegKey2Seed to differentiate yourself from other PLUS users. The evaluation copy of LFEdit does not permit changing the Trigger Code seed. Click on the EZ Trial Parameters Tab and change the properties as desired. Press F1 for a description of all of the fields and their purpose. You MUST leave "convert illegal copies to demo" checked. Click Ok to save all changes.

Create a License File in LFEdit

In LFEdit, click the New button on the toolbar. Click on the Expiration Fields Tab. Make sure the Expiration Type is D for Demo and that a hard expiration date is filled in. Even if you are letting the application run for an unlimited number of days, a hard expiration date must be filled in. To essentially disable the hard expiration date, fill in 12/31/2050. Save the License File.

Run Your Application

The application should run the number of days and times specified when you created the License File.

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 18 if not using Hardware Binding (copy protection) or 31 if Hardware Binding was selected on the EZ Trial Parameters Tab. 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.

Using EZ Trial on a Network

Because most network installations do not maintain synchronized clocks, it is important that the last used time is not verified between installations, especially when License File Aliases are used. Be sure to turn off "Update last used time" in the EZ Trial Parameters tab of the product definition. In the ActiveX control, it is necessary to also set the UseLastUsedTime property to False.

Also, when deploying your application on a peer-to-peer network along with copy protection, disable Software Binding and choose Hardware Binding COMPNO_NETNAME along with one or more other algorithms. The EZ Trial engine will automatically use COMPNO_NETNAME algorithm from all of the workstations and will use the other algorithms on the server. You will need to activate your application twice - once on the server and once on one of the workstations.

It is now recommended to run the application installed on a peer server using the UNC path or mapped drive letter, just as a workstation would, so only the COMPNO_NETNAME algorithm is used and only a single activation is required to enable the entire network.

More Information

You can optionally display the number of days or executions left in the trial using the DaysLeft and ExecutionsAllowed properties, respectively. To extend the number of days, use code 19 or 20. To extend the number of executions, use Trigger Code 25.

The sample application EZTrial1 is included to demonstrate another way to use both EZ Trial and EZ Trigger. There may be cases where EZ Trial does not offer the exact implementation that you are looking for. In this case, you can customize the software licensing features by referring to the other implementation topics in the manual.

Related Topics