Solved

EXE in EXE (Delphi 7)

Posted on 2004-03-23
11
773 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

751 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