adding files to the exe


i'm trying to make a installer program and making it so you only have the exe file. if anyone can show me some code without components would be a great help.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Use any archiver with self - extractor ;-))


I'm not sure u want to do that. Think about the memory management windows will do about that hudge .exe. Bad idea.
I don't have a copy of delphi handy here, but I can give the gist of it :)

You can append anything to the end of an exe, you just need some way of knowing how much is 'extra' so you could do something like this:

declare a record type to keep track of your size info, try:

 TAppendedFooter = record
   sig = array[0..3] of char;
   exeSize : cardinal;

put some 4 letter string into sig, so you know that this exe has appended files.  the exeSize is the size _before_ you append, fileSize(application.exename) would be the call here.

You can't write to your own exe file while it's writing, but you can read from it, so the idea is to start with 2 files (your exe plus the file to append) and end up with a third.  To be able to read your own exe try:

 exefs : TFileStream;
 exefs := TFileStream.create(application.exename,fmOpenRead or fmShareDenyNone);

note, I may have my constants wrong, you just need to open for read only with the none exclusive share settings.

create another filestream for your output (with write access, of course), copy everything from exefs, then copy your file to be appended, then copy your TAppendedFooter.  You can do this several times.

To extract those files, read the footer, create two dest. filestreams, write the first TAppendedFooter.exeSize bytes to one filestream (your new exe, minus the appended file) and the remaining, minus sizeOf(TAppendedFooter) to the other (your appended file).  Again, if your appended serveral files you should be able to do this several times.

Delphi comes with an "Express Installer"??

I thought that was the purpose for it but I never looked at it.

Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

classic_gamingAuthor Commented:
woah just tried the code loads of errors :-). i'll have a go later on getting it right if it works i'll add it as a answer.
classic_gamingAuthor Commented:
woah just tried the code loads of errors :-). i'll have a go later on getting it right if it works i'll add it as a answer.
Not to hard at all if your using Delphi 5.  I found this online a few days ago I was looking for the same solution.

Here is the answer:

1. Go up to FILE/ADD and add a text file.
In the text file add what ever resources you want, Example:
Every new line is a new resource.
(Make sure you copy these files into the same directory where your program files for delphi are).

2. Then save your project.  Make sure you save the text as filename.rc instead of filename.txt

3. Now go up to PROJECT/ADD and select the filename.rc file you just saved.

4. Do a complete Build on your program.
This imports the resource file and all the resources into your program executable.  You can see because your program.exe should be the size it was plus the files added.
Or use resxplor.exe under your delphi\demos\resxplor\ to open your program.exe and see under RCDATA the files you added.

4. Now when you want to extract these files and use them just create a procedure in code that does this:

procedure TForm1.GetResources(Sender: TObject);
  RS : TResourceStream;
  // Extract Mame Image
  RS := TResourceStream.Create( 0, 'JPG', RT_RCDATA);
  // Extract Mame Executable
  RS := TResourceStream.Create( 0, 'EXE', RT_RCDATA);

Thats it!

Original answer copied from:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I have some demos on my site

Delphi apps that modify themselves as they run
and some that add files to themselves (not res files)
and create a new exe with the files ready to be extracted
to disk :-)

The source code is there with some of the demos...
feel free to use them as a shell to write your installer
program if you like :-)

An unfinished version of my floppy disk imager is on the site.. 'EXE2A' it works well enough so that you can see how
an installer prog might work... it sucks in a 1.44 mb
floppy and compresses the data and adds it to the end of
it's own exe file... then it changes the 3rd byte of the
exe from a 'P' to an 'A' so that the next time it runs it knows it should display as if it were a different exe...
this trick works great and the 2 programs seem to be different exe's but they are actually the same one... just change the 'MZA' back to 'MZP' and the original comes
back... you could write an installer using the same method :-)
classic_gamingAuthor Commented:
i tested it and it worked fine :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.