Home » Support » User Manual » The Software Licensing System » Example of usage » Step #6: Limit application running time

Step #6: Limit application running time

You may limit time that application will work after starting. Licensing module will not terminate the application when time will run out, but it will set a corresponding flag in the serial number state. Let’s limit running time of our application by 1 minute. Add the following line to INI-file:

TimeLimit=1

We need to change our application a bit:

int main(int argc, char **argv)
{
	char *serial = "Xserialnumber";

	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;
}

After start our application prints serial number state, then reads number of minutes it is allowed to run, then sleeps this time and query state of serial number again. If we run the application, we’ll see the following:

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

Real protected application should check state of serial number periodically and terminate itself if the flag will appear. Licensing module doesn’t do that automatically because you may want not to terminate application but to block some features, or show messages, or allow user to save data etc. It is up to developer what to do when time is over. Licensing module will just inform about it.