Home » Support » User Manual » Licensing system » Integrating to application » Step 1.6: Limiting the operation time of the program

Step 1.6: Limiting the operation time of the program

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


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);
        if (res) return 0;

        VMProtectSerialNumberData sd = {0};
        VMProtectGetSerialNumberData(&sd, sizeof(sd));
        printf("I will run for %d minute(s)\n", sd.bRunningTime);
        Sleep(60 * 1000 * sd.bRunningTime);
        printf("After %d minute(s):\n", sd.bRunningTime);

        return 0;

The program prints the status of the serial number upon start up, then calculates the maximum operating time and waits it to expire. Then 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):

The protected program should analyze the status of a serial number periodically 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. Also, you may want the program to not stop after the operation time has expired, but instead switch to a more restricted mode. The licensing system leaves this up to the developer.

Next step