Write serial number to file using Inno Setup

泄露秘密 提交于 2020-12-31 10:42:59

问题


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) ?


回答1:


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, e.g.:

[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;


来源:https://stackoverflow.com/questions/25870729/write-serial-number-to-file-using-inno-setup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!