Get Demo
  • Windows
  • MacOS
  • Linux

Step 1.6: Limiting the operation time of the program

You can limit how long a program operates from the moment it is started. This can be useful for demonstration purposes: you provide a valid serial number to a user, but the program works for no longer than 5 minutes. The licensing system does not force such a program to shut down; it merely sets a status flag. So, let’s set a maximum working time of one minute by adding the following line to the INI file:

TimeLimit=1

And modify the program as follows:

int main(int argc, char **argv)
{
    char *serial = "Xserialnumber"; // we set the serial number directly in the code for simplicity
    int res = VMProtectSetSerialNumber(serial);
    print_state(res);
    if (res) return 0;
    VMProtectSerialNumberData sd = {0};
    VMProtectGetSerialNumberData(&sd, sizeof(sd));
    printf("I will run for %d minute(s)\n", sd.bRunningTime);
    print_state(VMProtectGetSerialNumberState());
    Sleep(60 * 1000 * sd.bRunningTime);
    printf("After %d minute(s):\n", sd.bRunningTime);
    print_state(VMProtectGetSerialNumberState());
    return 0;
}

The program prints the status of the serial number at startup, then calculates the maximum operating time and waits until it expires. After that, the serial number status is printed again. With the maximum operation time set to one minute, we should receive the following result:

state = 0
I will run for 1 minute(s)
state = 0
After 1 minute(s):
state = SERIAL_STATE_FLAG_RUNNING_TIME_OVER

The protected program should periodically check the status of the serial number and shut down if the flag is set. The licensing system does not do this automatically, because the program may need to free memory, save data to a file, and so on. You may also want the program not to stop after the operation time has expired, but instead switch to a more restricted mode. The licensing system leaves this decision to the developer.

Last updated 11 days ago