Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2007

Tip: Looking for answers? Try searching our database.

How to include an executable in the c# console project

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mo - 28 Nov 2007 17:19 GMT
Hi,

Is there a way to include an executable  (xxx.exe) file inside a c#
console project so that the resulting project binary have only one
final executable file? My c# console application is calling another
Executable (exe) which I am trying to include in my project so I can
only have one file for the executable. Any ideas?

Mo
Willy Denoyette [MVP] - 28 Nov 2007 17:34 GMT
> Hi,
>
[quoted text clipped - 5 lines]
>
> Mo

One .exe cannot *call* another exe, one .exe can only *start* another .exe,
and this requires both  .exe to be separate PE files.

Willy.
Nicholas Paldino [.NET/C# MVP] - 28 Nov 2007 17:37 GMT
Mo,

   Not that I know of.  You would have to include the other executable
separately.

   If the executable is self-contained, and has no dependencies that you
need to ship, then you could include the executable as a resource in your
main executable, then extract and save it to disk and execute it when
needed.  It would still require some cross-process communication to get the
results, but you would have one executable you have to ship.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Hi,
>
[quoted text clipped - 5 lines]
>
> Mo
Arnshea - 28 Nov 2007 18:10 GMT
> Hi,
>
[quoted text clipped - 5 lines]
>
> Mo

If I'm reading you correctly you may be able to include the 2nd
executable in the 1st project as an embedded resource.  The 1st
executable could read the embedded resource, write it out to a file,
then execute it.  Something along the lines of:

        static void Main(string[] args)
        {
            string outFile = args[0];

            Assembly asm = Assembly.GetExecutingAssembly();
            Stream stream =
asm.GetManifestResourceStream("EmbeddedEXETest.EmbeddedEXETest.exe");

            byte[] buf = new byte[4096];
            FileStream fOut = new FileStream(outFile, FileMode.Create);

            int bytesRead = 0;
            while ( (bytesRead=stream.Read(buf, 0, buf.Length)) > 0 )
                fOut.Write(buf, 0, bytesRead);

            stream.Close();
            fOut.Close();

            Console.WriteLine("Output written to {0}", outFile);
        }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.