EXE in EXE (Delphi 7)

well here it is: i´ve made an exe and what i want to do is make a new exe that will only "install" the other...
i mean: i have a program named "w" (is already compiled)... and what i want to do is to make another program that will only copy "w" to the windir and make it starts every time windows reboots...
i´ve already asked for the code i should use to copy a file and to make a registry key but now i would like to know how can i put "w" into my new program and how to extract it to the windir
i think i won´t be able to use the same code for copying a file to extract "w" because i don´t want to copy the whole application...
that´s the question: how can i include an exe in another exe and extract it to the windir
hope u can help me
thanks
lobo_esteparioAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
shaneholmesConnect With a Mentor Commented:
If you want this compiled into your exe, you will have to add the following under your implementation section

{R$ MyRESOURCEFILE.rc}

Shane
0
 
shaneholmesCommented:
Goto
http://www.geocities.com/gacarpenter386/

and download the following example code:

ExeInExe demo for Exiler 09/30/03

SHane
0
 
Russell LibbySoftware Engineer, Advisory Commented:

Might be easier to just embed the exe as an RC_DATA resource in the main exe, which can then be pulled out at a later point using FindResource/LoadResource....

Just my 2 cents,
Russell



0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
FrankTheRatCommented:
Why don't you just use Installshield?

FrankTheRat
0
 
lobo_esteparioAuthor Commented:
"Might be easier to just embed the exe as an RC_DATA resource in the main exe, which can then be pulled out at a later point using FindResource/LoadResource...."
how do i do that?
another question... where is the option to create a .rc file?
i can´t find it.... i´ve read about it and i know some stuff that could help me but i don´t know how to create a rc file and how to compile it
hope u can help me
0
 
shaneholmesCommented:

1.) Create a ascii text file using Notepad

place the following info in there

MyAPP RT_RCDATA MYAPP.exe
MyAPP2 RT_RCDATA MYAPP2.exe


save it with a .rc extension instead of a .txt extension

then use the command ine run  BRCC32.exe

Example

BRCC32 C:\Progra~1\borland\delphi7\projects\MyProject\MyResourceFile.rc


SHane

0
 
StTwisterCommented:
Delphi offers a great way to store any tipe of file (avi, wav, EXE etc.) in the application (executable) by supporting resource files.

There are few steps to be done:

Creating a resource script (RC) file
Create a file MyRes.rc. In this file put the following line:
xx wave MyFile.wav

In case of adding more files, the line above has to be repeated.
xx represents the identifier for the embedded file (an identifier, that can be any name, must be put for each file) and wave represents the file type. As it can be seen, the line format is:

[resourcename] [filetype] [filename]

and in case the type of the file isn't known, filetype can be replaced with RCDATA.

Compiling MyRes.rc
Compile the RC file to a RES file by typing in the command prompt:

brcc32 MyRes.rc

After this will result MyRes.res - the resource file.

Including MyRes.res file in the project
The resource file must be mentioned in the *.dpr file or in the *.pas file, under implementation as it can be seen below:
implementation

{$R *.dfm}
{$R MyRes.res}

Playing the wave
For playing the wave from the embedded file, the function below can be used:
PlaySound('xx',hInstance,SND_RESOURCE or SND_SYNC);


--------------------------------------------------------------------------------

Embedding executables

As I said earlier, it is possible to store anything in the exe, even another exe! You have to follow the same steps as for the wave file (see above), the single difference being that the file type is exefile, not wave, so the line in the resource script file will be:

q exefile MyExe.exe,

where q is the identifier.
A reason for putting an exe in another is to execute it while running the main or just extracting it on the hard disk for a later action ;-). For extracting the embedded file on the hard disk it can be used a procedure like this:


procedure TForm1.ExtractRes(ResType,ResName,
      ResNewName:String);
var ExeRes:TResourceStream;
begin
    ExeRes:=TResourceStream.Create
      (Hinstance,Resname,Pchar(ResType));
    ExeRes.SavetoFile(ResNewName);
    ExeRes.Free;
end;

And here is an example for calling the procedure ExtractRes:


procedure TForm1.FormCreate(Sender: TObject);
var SysDir:Array[0..Max_Path] of Char;
begin
    GetSystemDirectory(SysDir,Max_Path);
    ExtractRes('exefile','q',SysDir+'\MyExe.exe');
end;

0
 
lobo_esteparioAuthor Commented:
i made that... i was able to create a .rc file but when i used the brcc32 command it called visual studio net and then it created a .aps file but it didn´t create the .res file
do i have to uninstall visual studio net?
what is wrong with what i´m doing?
hope u can help me
0
 
lobo_esteparioAuthor Commented:
well i´ve just got the .res file what i want now is to run that program synchronously with the .exe that contains it
does it just run at start or is there any specific code to run the resource file?
0
 
StTwisterCommented:
the resource file is included in your application when compiled.

Just use the ExtractRes procedure as shown above to save the file on the disk and then run it with WinExec.
0
 
kamisergCommented:
you can use the exemod.pas unit.
http://www.torry.net/quicksearchd.php?String=exemod&Title=Yes
with this unit you can put in the exe anything in runtime.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.