2

I'd like to embed an executable inside of my Delphi binary and extract it at runtime. The purpose of this is to ensure that a helper utility is always available on the system, without having to distribute multiple files.

With Delphi 2007 I have used JvDataEmbedded, but I am building a console application and I want to know if anyone knows of another way to do it without having to add a hidden form for JvDataEmbedded.

I am using Delphi 2010.

3
  • 3
    The usual way to get multiple files onto the system without having to distribute them separately is to just use an installer. Commented May 4, 2010 at 0:09
  • 2
    @Mick: You do realize that this will most likely trigger most virus scanners to alert about malware, right? Commented May 4, 2010 at 12:47
  • @KenWhite - It doesn't for Process Explorer (which uses a similar method). And it hasn't on the machines I've tested against with my own utilities. Commented May 22, 2014 at 14:26

3 Answers 3

13

Build a RC file that embeds this program as a resource, and then at runtime you can extract it with a TResourceStream. (See the accepted answer to this question of mine for the general principle.) You can chain the TResourceStream to a TFileStream to write it out to a temp file, then run it.

Sign up to request clarification or add additional context in comments.

Comments

1

Cool Trick, Mason! To add... It occurred to me that this could run into trouble with UAC/permissions if the "mothership" dumps teh "scout ship" diretly into the same directory as it's running from. If you're on Vista/Windows7, regular programs are prevented from writing to the "\program files" directory, when run without elevated permissions. So in that case, the file will likely be placed into a shadow directory. It gets better: you may have different results if you launch the "mothership" program from an installer, as setup programs have special access, and they may temporarily give that access to programs that they launch (which makes it somewhat hazardous to always say YES to "do you want to run the program now?" at the end of installation).

Comments

1

Use a TDataModule to hold the TJvDataEmbedded instead of a TForm.

1 Comment

...or simply create the TJvDataEmbedded in code... or better yet, use Mason's approach

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.