How do I...?

Expire my Application After a Certain Number of Executions

To make your application expire after a certain number of executions, store a value in the registry the first time the program is run, and increment it every consecutive time the program is run. Then, every time the program is run, check the stored value.

To accomplish this:

  1. Insert the following code into the On Startup event of your project:

-- Set the number of times allowed
times_allowed = 30;

-- Retrieve the number of times run and convert the value to a number
times_run = Application.LoadValue("My Application", "Has Been Run");
times_run = String.ToNumber(times_run);

-- Calculate the number of allowed run times remaining
times_remaining = (times_allowed - times_run)

-- Check if this is the first time the application has been run
-- Save the new number of times run value
if times_run == 0 then
    Application.SaveValue("My Application", "Has Been Run", "1");
else
    Application.SaveValue("My Application", "Has Been Run", (times_run + 1));
end

-- Check if the application has been run more times than allowed
if times_run > times_allowed then
    Dialog.Message("Trial Period Over", "This software has expired");
    Application.Exit();
else
    Dialog.Message("Trial Period", "You can run this program "..times_remaining.." more times.");
end