-1

I want to add EXE files to my EXE console application. When my console application is triggered, all EXE files to be unzipped to a location I want. How can I do that? Like TeamViewer.exe program runs itself copying files to C:\Program Files (x86)\ or C:\Users\%USERNAME%\AppData\Roaming\TeamViewer.

  • 3
    So what you want is a [self-extracting archive](http://en.wikipedia.org/wiki/Self-extracting_archive)? – Some programmer dude Jan 10 '14 at 11:54
  • I want my EXE program to be able to put included programs in other directory. I want my EXE program to include all other EXE programs. I specify that I want a single file as my program, not an archive. – Hattrick HKS Jan 10 '14 at 11:56
  • @HattrickClaudiuHKS everything you have said still fits a self-extracting archive. Did you follow the link to see what it does? – Mike Beckerleg Jan 10 '14 at 12:11
  • I already created SFX archives and I know what is it. The thing I speak about it's almost like what you say, but in a SFX archive I'm not able to check whether the operating system has x64 or x86 architecture. I want to execute code with my program furthermore extracting the files. To be more explicit, Hattrick.exe will copy files from itself to C:\New Folder and furthermore, will execute C++ code. I use Visual Studio 2013 as student. – Hattrick HKS Jan 10 '14 at 12:15
  • You could try [this](http://www.chilkatforum.com/questions/2354/how-to-write-a-self-extractor-for-the-windows-os) self-extractor technique. Also, you could use a [resource file](http://msdn.microsoft.com/en-us/library/7zxb70x7.aspx) if you're using Visual Studio – Proxy Jan 10 '14 at 12:17
  • Windows resource files, added to the EXE with the rc compiler? – Martin James Jan 10 '14 at 13:36
  • How can I add an EXE resource (This.exe) to my Program.exe? If I click on project's properties then add resource, I only see icons, photos and so on... But not executable files. Furthermore, how to select the location I want them to be copied to? – Hattrick HKS Jan 10 '14 at 15:21
  • @HattrickClaudiuHKS - rename it to .bmp :) – Martin James Jan 11 '14 at 11:45

2 Answers2

0

You can just append extra bytes (payload) at the end of the file. For example you can append a ZIP file with the dependencies. You have a tiny tutorial here.

Then you have to code the extraction however you want. Let's call loader the part of your program that has to extract and install the dependencies and then run the original main function. If you can't run the exe without the dependencies already installed then you need to create an external loader with no dependencies and add the main exe as a dependency (inside the zip).

If the file is signed you might find helpful this question.

Community
  • 1
  • 1
aalku
  • 2,860
  • 2
  • 23
  • 44
0

You could put the file content in an array. Just create a tool that reads the file you want to embedd, and generates the following two files:

// exefile.c
const char exefile[] = {0xff, 0xff, 0xff,....};

and

// exefile.h
extern const char exefile[123456];
  • Interesting thing, but I don't think I can create a tool that read the file I want to embed. I only know to read text files. – Hattrick HKS Jan 12 '14 at 00:21