Search code examples
windowssecuritywindows-8installationinno-setup

InnoSetup - how to ask user to type license key or product key and match that code with compiled constant?


I have to distribute a setup.exe made using innoSetup, where per user and per PC it has to be licensed.

I was thinking to give them a license key/product key like Windows 8.1 which they have to type in the InnoSetup. and match it with embedded constant or live over internet. Once the validation is done then the setup.exe will be complete else it wont install.

Is there any sample for such with innosetup, how can i do that please?


Solution

  • To create a page for entering serial numbers you can enable the UserInfoPage directive and write a handler for the CheckSerial event:

    #define SerialNumber "123456"
    
    [Setup]
    AppName=My Program
    AppVersion=1.5
    UserInfoPage=yes
    DefaultDirName={pf}\My Program
    
    [Code]
    function CheckSerial(Serial: String): Boolean;
    begin
      Result := Serial = '{#SerialNumber}';
    end;
    

    INVALID Serial:
    enter image description here

    VALID Serial:
    enter image description here

    I have used a preprocessor defined constant because that allows you to simplify the build process. You can then define such constant from outside the script, with extended command line compiler and make e.g. a batch script that will build the setup with a defined serial number.

    You would just remove the first (hardcoded) line from the above script and run a command line like this (for serial number 654321):

    iscc "/dSerialNumber=654321" "C:\Script.iss"
    

    Of course in real you will need to take care about administration of the output setup files and their serial numbers but the system that you choose is upon you. Command line compiler allows you to specify the output path and a file name which is more than enough to build such system.