Contents - Index


4.4.3 Automatic Mode Event Handlers

Now your application is protected by Sheriff under its Automatic Mode, you might want to add some more features to your protection. Basically this adding some event handles to handle the events that might be fired up by Sheriff.

  1. The first event you might want to handle is OnTooManyUsers. This event is fired up by Sheriff when the concurrent user limit defined in the licence has been reached while a user is trying to login. In your event handler, you might firstly want to display a message box to say that there are too many users currently using the licence and then either exit the application or let the application continue to run for that user but only in demo mode with limited features.
  2. The event handler might look like this:

    Private Sub Sheriff1_OnTooManyUsers()
      MsgBox "There are too many users"
      'take appropriate action'
    End Sub
  3. In the event of an error, Sheriff will fire up the OnError message. This event message comes with two parameters: lErrorCode, bstrErrorMsg. lErrorCode is the error code of the problem and bstrErrorMsg is the error message.
  4. The event handler might look like this:

    Private Sub Sheriff1_OnError(ByVal lErrorCode As Long, ByVal bstrErrorMsg As String)
       MsgBox bstrErrorMsg
    End Sub
  5. If the Auto Trial is set on, Sheriff will automatically issue a trial licence (should the machine has never been licensed to run the application) ie. It is the very first time the user attempts to run the application. If a trial licence is issued successfully, Sheriff will then fire up the OnTrial message. If you wish to take any action when the trial licence is issued, such as presenting a message box to confirm that the user is now allowed to enter into the evaluation time, then you can handle OnTrail event.
  6. The event handler might look like this:

    Private Sub Sheriff1_OnTrial()
       MsgBox "You're now entering evaluation time"
       'take appropriate action'
       '...
    End Sub
  7. During the evaluation period you might want to check the usage of the licence and remind the user of the current licence status. For instance, you may check to see how many days the user is allowed to use the application and how many days are left. This task is accomplished by providing an event handler for the OnStart message. Sheriff fires up the OnStart message once the call to the CheckLicence method succeeds.
  8. The event handler might look like this:

    Private Sub Sheriff1_OnStart()
       MsgBox "OnStart"
       hr = Sheriff1.QueryLicenceInfo()
       'take appropriate actions
       '...
    End Sub
  9. If you elected not to let Sheriff automatically issue a trial licence or present its authorization dialog box when it detects that the machine has not been licensed, then Sheriff will fire up a OnProductNotAuthorized message. You need to handle this event in your code and provide your own dialog box or take whatever action that is appropriate to your requirements.
  10. The event handler might look like this:

    Private Sub Sheriff1_OnProductNotAuthorized()
       MsgBox "Product is not authorized"
       'take appropriate actions
       '...
    End Sub
  11. Finally, if you decided not to let Sheriff automatically present its renewal dialog box as soon as it detects the licence has expired, then Sheriff will fire up an OnLicenceExpired message. You need to handle this event in your code and provide your own dialog box or take whatever action that is appropriate to your requirements.
  12. The event handler might look like this:

    Private Sub Sheriff1_OnLicenceExpired()
       MsgBox "Licence Expired"
       'take appropriate action'
       '...
    End Sub