Using a Custom Action for Serial Number Validation

InstallShield 2019 Express Edition

Serial number validation requires the use of a custom DLL file. Example code for this type of DLL file is available in the following location:

InstallShield Program Files Folder\Samples\WindowsInstaller\ValidateSerialNumber

In this example, the serial number must take the following format:

Field1-1505-XXXXXXXXXX

The first section must appear as it does above, although it is not case-sensitive. The second section, 1505, must be a number evenly divisible by 5 (for example, 1111 would not work). The last section can be any 10 alphanumeric characters. Keep in mind that this format is merely an example. Your serial number function can take any format that you would like it to have.

Filter the Input Characters

To filter the input from illegal characters, enter ??????-####-?????????? in the Serial Number Template field for the Customer Information dialog in the Dialogs view. The question marks (?) signify alphanumeric characters and the number signs (#) signify numbers. By setting the template in this manner, your serial number field is separated into three parts, and each section is filtered for different types of input.

Further Considerations

The Validate Function, Success Return Value, and Retry Limit properties allow you to further customize how your serial number validation DLL file works. For the Validate Function property, enter the name of the function within your .dll file that validates the serial number provided by the end user.

Your .dll file should return a specific value every time it is run. The example .dll included with InstallShield returns 1 on success and –1 on failure. Therefore, type 1 in the Success Return Value field. When you write your own .dll file, the success return value can be whatever you choose, as long as it is non-zero.

The Retry Limit property lets you set how many failed attempts are allowed. For example, if you only want users to be able to try entering a serial number three times, type 3 in this field. After the third failed attempt, the installation exits.

The example .dll file contains a user interface element that breaks down the entered serial number and displays it to the user. Additionally, it displays the section, if any, of the serial number that is incorrect. This display is useful when testing and troubleshooting your serial number verification .dll file, but it should not be left in the final version of your installation.

Note • InstallShield sequences the serial number DLL file custom action after any user-defined custom actions. Thus, if you add your own custom action and schedule it after the Customer Information dialog, the installation launches this custom action before the serial number DLL file custom action.

See Also