How can I create a txt file with Inno Setup?

49 Views Asked by At

How can I create a txt file in a folder with Inno Setup?

[Run]
SaveStringToFile('c:\filename.txt', #13#10 + 'the string' + #13#10, True);

The code doesn't work, what's the problem here?

1

There are 1 best solutions below

0
Martin Prikryl On

You need to call the code (SaveStringToFile) from an event function or possibly from a UI-control handler. You didn't specify when you want the file to be created. Assuming you want to create it as part of the installation, you can use CurStepChanged event function in ssInstall (pre-install) or ssPostInstall steps.

[Code]
procedure CurStepChanged(CurStep: TSetupStep);
begin
  if Step = ssPostInstall then
  begin
    SaveStringToFile('c:\filename.txt', #13#10 + 'the string' + #13#10, True);
  end;
end;

Though hard-coding C: drive seems like a bad idea.