Solved

EXE in EXE (Delphi 7)

Posted on 2004-03-23
11
775 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month3 days, 21 hours left to enroll

630 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