简体   繁体   中英

Write serial number to file using Inno Setup

I am trying to get the following Inno Setup code to work:

[Setup]
UserInfoPage=yes

[Code]
function CheckSerial(Serial: String): Boolean;
begin
  Result := true;
  SaveStringToFile('c:\Registration.txt', Serial, False);
end;

The code is extremely simple when the file path is known at UserInfoPage . However it becomes extraordinarily complex when I need to write this file next to my application. Neither:

WizardDirValue();

nor

ExpandConstant('{app}');

do work. The first one is empty when called too early and the second one does not even run, I get:

Internal error: an attempt was made to expand the "app" constant before it was initialized.

How does one store the Serial value to a file which needs to resides next to the application (.exe file) ?

You can expand the {userinfoserial} constant to get the serial number that the user entered in the info page in some event fired after the application directory is chosen, eg:

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

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then
  begin
    SaveStringToFile(ExpandConstant('{app}\Serial.txt'),
      ExpandConstant('{userinfoserial}'), False);
  end;
end;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM