HOWTO: Make an AutoPlay Application Expire

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Support
    Forum Member
    • Jan 2000
    • 204

    HOWTO: Make an AutoPlay Application Expire

    HOWTO: Make an AutoPlay Application Expire

    HOWTO: Make an AutoPlay Application Expire

    Document ID: IR04019
    The information in this article applies to:
    • AutoPlay Media Studio 4.0

    SUMMARY

    This article explains how to make an AutoPlay application expire.

    DISCUSSION

    Note: Adding an expiration feature to your AutoPlay application will cause only the AutoPlay application to expire, all other data on your CD-ROM will not expire.

    In this article we will look at two popular methods that can be used to make an AutoPlay application expire. You can either make the application expire relative to the date, or make it expire by the number of uses. Date expiration means that the end user will be able to access your AutoPlay application until a certain date, after which it will stop working. Usage expiration means that your application will only run a certain number of times on a particular end user's system, after which it will cease to function.

    Date Expiration

    Here we will look at two methods that can be used with the date expiration method. The first is when you want your application to expire after an absolute date. The second is when you want the application to cease to work a certain number of days after the user first runs it.

    Note: When you are using date expiration you should always use Julian dates. A Julian date is an integer value representing the number of days since midnight on January 1, 4713 B.C. This makes it easy to perform mathematical calculations on the date.

    For example, let's sat that we want our AutoPlay application expire on January 1, 2004. The first step is to calculate what that date is as a Julian date. An easy way to determine any particular date in Julian representation is to use the System.GetDateTime action to get the current date to a variable and then display the contents of the variable on the screen in a Text object. Now just set your system's date ahead to the desired date and run the test application. In this example, January 1, 2004 is 2453006 as a Julian date.

    Now, to make the AutoPlay application expire all that we need to do is to compare the current date, that is the date on which the user is running the application, to the absolute date on which we want to make it expire. If the current date on the user's system is greater than the expiration date (January 1, 2004) we can then end the application. Below is an example of how to set this up. All of these actions are performed on the Project's "On Initialize" event.

    %Date% = System.GetDateTime ( "Date", "Julian Date")
    IF (%Date% >= 2453006)
    %Result% = Dialog.MessageBox ("Expired", "This application has expired.", Ok, Stop)
    Application.Exit
    END IF

    Now for the second case, where we want to make the application expire a certain number of days after the application is first run on the user's system. For this example, we will make the application expire 30 days after it is first run. This case is very similar to the first case, except that we do not know an abosulte date of expiration. To do this, we will write out the date that the application is first run to the Registry and then do our comparisons based on that date.

    The first step is to check if the "date" Registry value exists. If it does exist, then we will compare the current date to that date. If it does not exist, we will write our calculated expiry date to the Registry. Then we will run the date comparison in a similar way to the previous example. Again, all the actions will take place on the Project's "On Initialize" event.

    %Date% = System.GetDateTime ( "Date", "Julian Date")
    %ExpDate% = "FALSE"
    %ExpDate% = Registry.GetValueData ("HKEY_CURRENT_USER\HiddenKey", "Date")
    IF (%ExpDate% = FALSE)
    %ExpDate% = Evaluate (%Date% + 30)
    Registry.SetValue ("HKEY_CURRENT_USER\HiddenKey", "Date", "%ExpDate%")
    END IF
    IF (%Date% >= %ExpDate%)
    %Result% = Dialog.MessageBox ("Expired", "This application has expired.", Ok, Stop)
    Application.Exit
    END IF

    Usage Expiration

    Usage expiration is similar to the second example in the previous section in that we will use the Registry to store data for the operation. In this case, we will store the number of uses in the Registry. We will read the current number of runs from the Registry, and increment it if it exists. If it does not exist, then we will create the value and initialize it to one. As with the other examples, these actions will take place on the Project's "On Initialize" event.

    %NumRuns% = "0"
    %NumRuns% = Registry.GetValueData ("HKEY_CURRENT_USER\HiddenKey", "NumberOfRuns")
    IF (%NumRuns% = 0)
    %NumRuns% = "1"
    Registry.SetValue ("HKEY_CURRENT_USER\HiddenKey", "NumberOfRuns", "%NumRuns%")
    END IF
    IF (%NumRuns% >= 30)
    %Result% = Dialog.MessageBox ("Expired", "This application has expired.", Ok, Stop)
    Application.Exit
    ELSE
    %NumRuns% = Evaluate (%NumRuns% + 1)
    Registry.SetValue ("HKEY_CURRENT_USER\HiddenKey", "NumberOfRuns", "%NumRuns%")
    END IF

    Tip: You might want to create a second "hidden" registry key that gets created when the application is run for this first time, and then check to make sure that both exist. If one exists and the other does not you know that the user has tampered with the Registry and that the application should be closed.

    MORE INFORMATION

    For more information please see the following topics in the AutoPlay Media Studio 4.0 Help:

  • Command Reference | Actions | Registry | Get Value Data
  • Command Reference | Actions | Registry | Set Value
  • Command Reference | Actions | Control Structure | IF
  • Command Reference | Actions | Control Structure | END IF
  • Command Reference | Actions | System | Get Date Time
  • Command Reference | Actions | Dialog | Message Box
  • Command Reference | Actions | Variable | Set Value
  • KEYWORDS: AutoPlay Media Studio 4.0, Expiration, Date Expiration, Usage Expiration, Security


    Last reviewed: October 22, 2002
    Copyright © 2002 Indigo Rose Corporation. All rights reserved.
Working...
X