I need to copy a file to one folder, before Inno Setup starts or before the “select directory” page. I want this file to be copied from the installer and not from an external source.
I am using this code:
function NextButtonClick(PageID: Integer): Boolean;
begin
Result := True;
if (PageId = wpWelcome) then
begin
FileCopy(
ExpandConstant('file.exe'),
ExpandConstant('{reg:HKCU\SOFTWARE\XXX,InstallPath}\file.exe'), false);
end;
end;
To extract a file from the setup archive any time you need you’ll have to use
ExtractTemporaryFileprocedure. This procedure extracts the file from the[Files]section to a temporary directory used by the setup application, which you can find on the path specified by the{tmp}constant. Then you’ll just copy such extracted file to a target directory from there by expanding the mentioned constant.If you want to do something when the setup is being initialized, but before the wizard form is created, use the
InitializeSetupevent function. Note, that you can even exit the setup from that function without seeing the wizard form e.g. if the file you’re going to copy is critical that much. Here’s a sample code, but first take a look at thecommented versionof it for some details: