Link to home
Start Free TrialLog in
Avatar of ryan_sabarre
ryan_sabarre

asked on

combining 2 exe program

can i combined 2 exe program?
ex. FIRST exe is the original one
    eg. NOTEPAD.EXE
    SECOND exe is my program which is
    a delphi program that ask password.

    the two are combined together in which when you
    run the NOTEPAD.exe file the SEcond exe file
    will execute first asking for password when the
    user inputed the correct password then the program
    NOtepad will execute.
    It must be 1 exe filename which is the ORIGINAL
    FILE (notepad.exe) or others.

    and also identify if NOTEPAD.exe is terminated.

thank you in advance.
Avatar of alanwhincup
alanwhincup

Listening...
Yes you can do this :-)

There are several ways...if I were doing it I would tack the 2nd exe onto the end
of the first... have the first ask for the password..then eject number 2 exe out to
the disk and run it... I'm not sure about how to tell when the 2nd exe has terminated
but I think that's a simple matter :-)

I can write you a working demo (except for the determining 2nd termination part)
 
I am working on a Unit to handle tasks just like this one... if you wait till it's done
you can do this kind of thing with just a few lines of code..and add the 2nd exe to
your main exe after it is compiled ... easier than doing it during a compile I think...
and easier to change things later without using delphi to do it...

Another way to do this is to simply put your 2nd exe into a res file and add it to your
main program..then write it to disk when the password is entered correctly... this
will work just fine... but I don't ever do it this way... there are lots of EE gurus that
can explain how to do it this... I'm sure one will be along shortly  :-)

p.s. If what you want is to be able to place a password shell around any other windows
exe...that is doable also.... but people won't like you comandeering a program like
notepad.exe and making it into a pw protected file ;-) all you need to do is make a
self modifying delphi exe that reads in the notepad.exe and adds it to itself... then it erases
the original notepad.exe... renames itself to notepad.exe and takes over ;-) now when you
run notepad.exe your delphi code runs first..asks for pw and if pw is correct it writes a
copy of the original notepad.exe to windows.temp and runs it.... then lurks in the background
waiting for notepad to finish...then erases it from the temp dir...... people won't like this sort
of business though ... and a real geek will figure it out in a nanosecond ;-)

And to add to Gwena's comment, people running windows 2000 will definitely be ticked because a program that does that will cause the window file protection stuff to constantly gripe about notepad.exe being overwritten, if it evens allows it to happen at all... Yes, notepad.exe is considered a protected operating system file in windows 2000, dont blame me I am just the messenger :)

Heath
Hi,
to further give along what gwena was mentioning about putting the second exe in the firsts res file (so it is compiled into first exe here is sample:

with notepad make a .rc file that looks like:

 TESTFILE  EXEFILE C:\windows\notepad.exe
and save as myres.rc then
compile it with brcc32.exe(in delphi bin) to get myres.res
add this myres.res in your projects directory so it can find it then in the unit do:

{$R *.DFM}
{$R MYRES.RES}

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

procedure TForm1.Button1Click(Sender: TObject);
begin
ExtractRes('EXEFILE','TESTFILE','C:\TEST_EXE_FROM_RES.EXE');
if edit1.text = 'mypassword' then
ShellExecute(Form1.Handle,'open','c:\Test_exe_from_res.exe',nil,nil,SW_SHOWNORMAL)
else
showmessage('invalid password');
end;


>> also identify if NOTEPAD.exe is terminated.

add this into the buttons proc using shellexecuteex instead of shellexecute as i did above and use with waitforsingleobject()

var
Form1: TForm1;
Ph: Thandle = 0;

implementation

{$R *.DFM}

uses shellapi;

procedure TForm1.Button1Click(Sender: TObject);
Var
exInfo: TShellExecuteInfo;
Begin
FillChar( exInfo, Sizeof(exInfo), 0 );
With exInfo Do Begin
cbSize:= Sizeof( exInfo );
fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_FLAG_DDEWAIT;
Wnd := GetActiveWindow();
ExInfo.lpVerb := 'open';
lpFile:= 'c:\Test_exe_from_res.exe');
nShow := SW_SHOWNORMAL;
End;
// could add a if fileexists(filename) then begin
// here first for checking..

If ShellExecuteEx( @exInfo ) Then Begin
Ph := exInfo.HProcess;
End
Else
ShowMessage(SysErrorMessage( GetLastError ));
while WaitForSingleObject(ExInfo.hProcess, 50) <> WAIT_OBJECT_0 do
 Application.ProcessMessages;
CloseHandle(Ph);
showmessage('process finished');
//could call deletefile('c:\Test_exe_from_res.exe');
// here or something if you want to..
end;

well just some more ideas for the soup:-)
Regards Barry
listening ...
ASKER CERTIFIED SOLUTION
Avatar of RickHalle
RickHalle

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just wanted to add.

If you want to check if YOUR notepad is terminated, before running it collect all active processes (windowed aps) - you can do it with WinAPI then run program and collect again. Now find out which one is yours.
Of course, you could just try to find handle to program by window name, but that is unsafe as there can be more Notepads opened.
Hi,
I also have a question, I know it's not my thread :)
Is this not a problem that you save the exe to a temp filename. Because that wait I can make a copy of the exe while it is running, and next time I won't have to provide a password because the exe will no longer be protected.
Is there a wait to create a process from an exe that comes from a ressource directly. There must be a wait I think. Something like upx packer ? (http://upx.tsx.org)
I can afford the points if you need motivation :)
Thanks,
John
Hi jeurk :-)

  It is possible to tack a dll onto an exe and run the code contained in it without
ever writing it to disk... http://www.collakesoftware.com/pebundle.htm
But I have never seen a way to run an exe that remains attached to another exe..
That would really be cool though :-)
==============================
Hi RickHalle  :-)

That's a nice piece of code :-)
Thanks Gwena, There actually was a bit more that entailed extracting a dll that Tmp.exe requires prior to extracting Tmp.exe. This dll is deleted by Tmp.exe when it closes yet is a resource in the wrapper. That prevents the exe from being grabbed during execution and moved. Even if it is then it will render itself useless. The only way around it is to grab both the exe and dll. Then put them in the folder every time it is run. This is enough to confuse and discourage almost anyone trying to bypass it.

Rick
Hello Gwena,
UPX is doing it and because it's an opensource project if we want to know how to do, we *just* have to look at the source code ;)
Are all the computers you show on your site working ? ;)
See you...

Hi jeurk :-)

>>UPX is doing it and because it's an opensource project if we want to know how to do, we *just* have
                     to look at the source code ;)

Yes but it's written in 'C' and my brain is way too small to figure out C source code...it all
looks like a Chinese suicide note to me ;-)

Actually I can't decide if I'm too stupid to program in C++ or too smart ;-)  I'll just use Delphi!

  I meant really that I have never seen a way to add a delphi exe to another and have
it run.... There are freeware programs that will add an asm or c executable to a windows
file and run that code first... I think mostly this is used for malicious things :-(  but
it is also used for things like UPX....   I would LOVE for someone to show me how to
add a delphi exe to another and have the delphi code run first..... it is also possible
to make a program that runs in dos or windows... it's actually 2 programs in one...
I think that the code that normally displays 'This Program Requires Windows' is somehow
replaced by asm code that runs a program in dos.... I'd like to know how to do this too :-)


Yes all those computers run.... and there are a bunch more over on the 'messy' side
of the room ;-)   The 2 big ones on the right are old junky 386-40's  good for only running
old dos or asm stuff....I use them when I build simple hardware stuff to be controlled by
the ports in asm....(a girl with a soldering gun is a dangerous thing ;-)
Avatar of ryan_sabarre

ASKER

Thank you i have nothing to say but you gave me an IDEA.