Solved

EXE in EXE (Delphi 7)

Posted on 2004-03-23
11
764 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:lobo_estepario
  • 3
  • 3
  • 2
  • +3
11 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10664073
Goto
http://www.geocities.com/gacarpenter386/

and download the following example code:

ExeInExe demo for Exiler 09/30/03

SHane
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 10664417

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
 
LVL 1

Expert Comment

by:FrankTheRat
ID: 10665594
Why don't you just use Installshield?

FrankTheRat
0
 

Author Comment

by:lobo_estepario
ID: 10673756
"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
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10673883

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 11

Accepted Solution

by:
shaneholmes earned 75 total points
ID: 10673897
If you want this compiled into your exe, you will have to add the following under your implementation section

{R$ MyRESOURCEFILE.rc}

Shane
0
 
LVL 2

Expert Comment

by:StTwister
ID: 10707415
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
 

Author Comment

by:lobo_estepario
ID: 10710168
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
 

Author Comment

by:lobo_estepario
ID: 10710183
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
 
LVL 2

Expert Comment

by:StTwister
ID: 10715266
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
 

Expert Comment

by:kamiserg
ID: 10849556
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now