Home » Support » User Manual » The Software Licensing System » Example of usage » Step #9: Lock serial number to hardware

Step #9: Lock serial number to hardware

Retrieving hardware identifier

To lock serial number to hardware, you need to get a hardware identifier first. This identifier will be stored in serial number and licensing module will check it while validating serial number. So, first of all, let’s get our hardware identifier. Change the main() function, so it will look like:

int main(int argc, char **argv)
{
	int nSize = VMProtectGetCurrentHWID(NULL, 0);
	char *buf = new char[nSize];
	VMProtectGetCurrentHWID(buf, nSize);
	printf("HWID: %s\n", buf);
	delete [] buf;
	return 0;
}

Run the application and you will see a default hardware identifier for the test mode:

HWID: myhwid

To change default identifier – add the following line to INI-file:

MyHWID=test

And run the application again. Now our hardware identifier is “test”:

HWID: test



Lock serial number to hardware identifier

Let’s tell our test licensing module that serial number is locked to hardware identifier. Add the following line to
INI-file:

KeyHWID=test

And we’ll need to change main() function a bit:

int main(int argc, char **argv)
{
	int nSize = VMProtectGetCurrentHWID(NULL, 0);
	char *buf = new char[nSize];
	VMProtectGetCurrentHWID(buf, nSize);
	printf("HWID: %s\n", buf);
	delete [] buf;

	char *serial = "Xserialnumber";
	int res = VMProtectSetSerialNumber(serial);
	print_state(res);
	return 0;
}

Run the application and you will see the following:

HWID: test
state = 0

As we may see, the licensing module compared two identifiers: hardware and the one that we put to the serial number. As they are the same, VMProtectSetSerialNumber() returned 0 – serial number was accepted.

Now let’s try to run the application on another hardware. Let’s replace “test” value for MyHWID parameter in INI-file to something different, for example “new test”. And run the application again:

HWID: new test
state = SERIAL_STATE_FLAG_BAD_HWID

As we may see, licensing module returned SERIAL_STATE_FLAG_BAD_HWID flag, that means that serial number is not accepted because of invalid hardware identifier. If we’ll replace value of KeyHWID parameter with “new test” and run the application one more time – we’ll see that licensing module will accept the new serial number.