accpert.com
accpert.com

Reputation: 129

Allow running Inno Setup installer only once

I would like to give some free copies of my software to some user, but I would like to prevent that the Inno Setup installer is also run on other computers. So I would like the installer to run only once on one computer and then never again.

Upvotes: 1

Views: 810

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202594

Make an online service, which your installer will check to determine, if the installation is allowed. The service shall count the installations and respond accordingly.

function InitializeSetup(): Boolean;
var
  WinHttpReq: Variant;
begin
  Result := False;

  Log('Checking installation online...');
  try
    WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
    WinHttpReq.Open('GET', 'https://www.example.com/install_check.php', false);
    WinHttpReq.Send();
    if WinHttpReq.Status = 200 then
    begin
      Log('Installation was allowed...');
      Result := True;
    end
      else
    begin
      Log(Format('Installation was not allowed with %d: %s...', [
        WinHttpReq.Status, WinHttpReq.StatusText]));
      MsgBox('Installation is not allowed.', mbError, MB_OK);      
    end;
  except
    Log(Format('Installation check failed: %s', [GetExceptionMessage]));
    MsgBox('Error checking if the installation is allowed.', mbError, MB_OK);      
  end;
end;

A trivial server-side validation PHP script (install_check.php) would be like:

<?

$flag_file = "/data/install_check";
if (file_exists($flag_file))
{
    $msg = "This installer was already installed";
    header("HTTP/1.0 401 $msg");
    echo $msg;
}
else
{
    echo "Can install";
    touch($flag_file);
}

Related question:
Inno Setup - How to validate serial number online


Though it's easy to extract the files from Inno Setup installer anyway. You can improve that by encrypting the installation and retrieving the decryption password from the online service.

By not returning the password, you will effectively prevent the installation.

See Read Inno Setup encryption key from Internet instead of password box

Upvotes: 1

Related Questions