PDA

View Full Version : HOWTO: Make an AutoPlay Application Expire



Support
10-09-2002, 11:10 AM
<HTML><HEAD><TITLE>HOWTO: Make an AutoPlay Application Expire</TITLE></HEAD><BODY><h3>HOWTO: Make an AutoPlay Application Expire</h3><b>Document ID: IR04019</b><hr>The information in this article applies to:<ul><li>AutoPlay Media Studio 4.0</li></ul><hr><h3>SUMMARY</h3><p>This article explains how to make an AutoPlay application expire.</p><h3>DISCUSSION</h3><p><b>Note:</b> Adding an expiration feature to your AutoPlay application will cause only the AutoPlay application to expire, all other data on your CD-ROM will <b>not</b> expire.</p><p>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.</p><p><b>Date Expiration</b></p><p>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.</p><p><b>Note:</b> 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.</p><p>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 <b>System.GetDateTime</b> 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.</p><p>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.</p><pre><code>%Date% = System.GetDateTime ( "Date", "Julian Date")<br>IF (%Date% >= 2453006)<br> %Result% = Dialog.MessageBox ("Expired", "This application has expired.", Ok, Stop)<br> Application.Exit<br>END IF</code></pre><p>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.</p><p>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.</p><pre><code>%Date% = System.GetDateTime ( "Date", "Julian Date")<br>%ExpDate% = "FALSE"<br>%ExpDate% = Registry.GetValueData ("HKEY_CURRENT_USER\HiddenKey", "Date")<br>IF (%ExpDate% = FALSE)<br> %ExpDate% = Evaluate (%Date% + 30)<br> Registry.SetValue ("HKEY_CURRENT_USER\HiddenKey", "Date", "%ExpDate%")<br>END IF<br>IF (%Date% >= %ExpDate%)<br> %Result% = Dialog.MessageBox ("Expired", "This application has expired.", Ok, Stop)<br> Application.Exit<br>END IF</code></pre><p><b>Usage Expiration</b></p><p>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.</p><pre><code>%NumRuns% = "0"<br>%NumRuns% = Registry.GetValueData ("HKEY_CURRENT_USER\HiddenKey", "NumberOfRuns")<br>IF (%NumRuns% = 0)<br> %NumRuns% = "1"<br> Registry.SetValue ("HKEY_CURRENT_USER\HiddenKey", "NumberOfRuns", "%NumRuns%")<br>END IF<br>IF (%NumRuns% >= 30)<br> %Result% = Dialog.MessageBox ("Expired", "This application has expired.", Ok, Stop)<br> Application.Exit<br>ELSE<br> %NumRuns% = Evaluate (%NumRuns% + 1)<br> Registry.SetValue ("HKEY_CURRENT_USER\HiddenKey", "NumberOfRuns", "%NumRuns%")<br>END IF</code></pre><p><b>Tip: </b>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.</p><h3>MORE INFORMATION</h3><p>For more information please see the following topics in the AutoPlay Media Studio 4.0 Help:</p><li><b>Command Reference | Actions | Registry | Get Value Data</b></li><li><b>Command Reference | Actions | Registry | Set Value</b></li><li><b>Command Reference | Actions | Control Structure | IF</b></li><li><b>Command Reference | Actions | Control Structure | END IF</b></li><li><b>Command Reference | Actions | System | Get Date Time</b></li><li><b>Command Reference | Actions | Dialog | Message Box</b></li><li><b>Command Reference | Actions | Variable | Set Value</b></li><p>KEYWORDS: AutoPlay Media Studio 4.0, Expiration, Date Expiration, Usage Expiration, Security</p><hr><FONT SIZE=1>Last reviewed: October 22, 2002<br>Copyright 2002 <A HREF="http://www.indigorose.com" target="blank">Indigo Rose Corporation</a>. All rights reserved.<br></FONT></BODY></HTML>