Command Reference - Action Examples
|
Actions used: |
In this example, we'll show you how to make your AutoPlay application expire 30 days after the first time the user runs it on their system, by recording the date in the Registry when the user runs the application for the first time.
Note that this won't prevent the user from running the application on another system, or from running it again if they reformat their system, or even if they simply delete that value from Registry. It also won't protect any files that are distributed with the application; it only prevents the user from running the application itself. For example, if you're distributing your application on a CD-ROM, making the application expire won't protect the contents of the CD. For that, you'll need to investigate other security technologies.
Here's what the action list looks like:

First, we use a "System - Get Date Time" action to get the current date (when the application is run) in Julian Date format, and store it in a variable called %JulianDate%.
(A Julian Date is an integer value representing the number of days since midnight on January 1, 4713 B.C. For example, the Julian Date for September 23, 2002 is 2452541, and the Julian Date for September 24, 2002 is 2452542.)

Then we use a "Variable - Set Value" action to assign a default value to the variable %FirstRunDate%, which is where we're going to store the Julian Date that we'll retrieve from the user's Registry. Setting a default value for the variable will give us an easy way to detect whether our "Registry - Get Value Data" action failed. (That action will assign a value to %FirstRunDate% if it succeeds; if the value in %FirstRunDate% doesn't change from our default value of "NOTFOUND", then we'll know the action failed.)

Now that we have our default value set up, we'll try to get the first-run date from the Registry. (In other words, we'll retrieve the Julian Date that our application will write the first time it was run on this PC.) For this, we use a "Registry - Get Value Data" action to get the same Registry value that we'll write out when the user runs this application for the first time.

If this is the first time that our application has run, the Registry value won't exist yet, and the "Registry - Get Value Data" action will generate an error, because it can't find the Registry value we told it to access. We don't need the user to be told about the error, though, so we'll change the User Notification settings on the On Error tab for this action from "Verbose" to "None".

This will prevent the action from notifying the user about this error.
Next we use a "Control Structure - IF" action to test whether the "Registry - Get Value Data" action failed.

If %FirstRunDate% wasn't changed by the "Registry - Get Value Data" action, then presumably this is the first time the user has run our AutoPlay application, because the Registry value doesn't exist. So, we use a "Variable - Set Value" action to set %FirstRunDate% to the current date...

...and then we use a "Registry - Set Value" action to write that date value to the Registry.

Note that we're using a somewhat "sneaky" name for the Registry value. Since a Julian Date is just a large integer, it isn't that obvious that it's a date...calling it something that sounds technical like "Device Address" will make it a bit less likely for the user to figure out what it is, and makes it sound like something they shouldn't be deleting. Of course, in your own projects, you'll want to adjust the name of the Registry key where this value is located, since "Expiring 30 days after running the first time" kind of gives it all away. :)
Next, we use a "Control Structure - END IF" action to end this IF block. That ends the block of actions that will only be performed if the Registry value doesn't exist.
At this point, we have values in both %JulianDate% and %FirstRunDate%, so we can proceed with the actual date calculation.
So, we use a "Control Structure - IF" action to test whether the difference between the current date (%JulianDate%) and the first run date (%FirstRunDate%) is greater than 30.

Subtracting the first run date (%FirstRunDate%) from the Julian Date at run time (%JulianDate%) gives us the number of days that have elapsed since the first time the application was run on this PC; if that number is greater than 30, our application was first used on this PC more than 30 days ago. (Note that we used parentheses in the conditional expression so the subtraction happens first, and then the result of the subtraction is compared to 30.)
If the result of this test is true, then the user has had at least 30 days to use our application, and we want it to expire. We should probably tell the user what's happening, so next we use a "Dialog - Message Box" action to explain that the application has expired, and give them a URL where they can get a newer version.

(We could make things even easier for the user by opening that URL automatically with a "File - Open" action, or even automatically downloading the newer version with a "Internet - Download Web File" action. But for this example, a simple message will do.)
Next, we use an "Application - Exit" action to exit immediately from the AutoPlay application.
Finally, we use an "Control Structure - END IF" action to end the IF block.
Here's a link to the finished example, as an AutoPlay Media Studio 4.0 actions XML file that you can import into an action list:
Expiring_30_days_after_running_the_first_time.zip
(Note: save this file to your hard drive and use a tool like WinZip to extract the XML file)