Solved

EXE in EXE (Delphi 7)

Posted on 2004-03-23
11
766 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
delphi custom sort exception 6 132
oracle global variables 4 63
how can i search if string exist in array ? 3 49
Adoquery sql  left join does not work 25 80
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

17 Experts available now in Live!

Get 1:1 Help Now