How do I insert a binary into a Delphi executable and extract it at runtime?

I would like to embed an executable inside a Delphi binary and extract it at runtime. The purpose of this is to make the helper utility available on the system without having to distribute multiple files.

Since Delphi 2007 I have been using JvDataEmbedded , but I am building a console application and I want to know if anyone knows of another way to do this without adding a hidden form for JvDataEmbedded.

I am using Delphi 2010.

+2


a source to share


3 answers


Create an RC file that inserts this program as a resource, and then at runtime you can retrieve it using TResourceStream. (See the accepted answer to this question of mine for a general guideline.) You can bind a TResourceStream to a TFileStream to write it to a temporary file and then run it.



+13


a source


Cool trick, Mason! To add ... It occurred to me that this might run into UAC / permission issues if the Mothership dumps the scout ship to the same directory it is running in. If you are running Vista / Windows7, regular programs cannot write to the "\ program files" directory when run without elevated permissions. Therefore, in this case, the file will most likely be placed in the shadow directory. It gets better: you may have different results if you run the "Mothership" program on the installer, since the installers have special access, and they can temporarily grant that access to the programs that run (which makes it somewhat dangerous to always say YES want do you run the program now? "at the end of the installation).



+1


a source


Use TDataModule to store TJvDataEmbedded instead of TForm.

+1


a source







All Articles