We help IT Professionals succeed at work.

How to embed a exe into a C# program

fxp007
fxp007 asked
on
I want to run a simple login code before the main "exe" file being executed of which I don't want to rewrite the code. I hope to compile them into a single file instead of separated two. How to archive it?
Thanks a lot.
Comment
Watch Question

anarki_jimbelSenior Developer

Commented:
If I understand properly your question - you can't do that.
I believe changing code - would be a right solution.
Howdy

Ive looked at this question a couple of time and thought about posting, you 'could' embed the executable in a resource file in your wrapper application, extract the executable if the logins correct and then execute it. Capture the process ending and delete the executable before closing your wrapper app. There is an example here of embedding an exe in such a way http://www.cs.nyu.edu/~vs667/articles/embed_executable_tutorial/

I completely agree that changing code would be the better way to go but if youve done due diligence then I hope this helps.

Author

Commented:
Thanks for reply
I see some solution that implement a C# program invoke a C# "exe" file. But I can't found a solution that could invoke a arbitrary "exe" file.
anarki_jimbelSenior Developer
Commented:
"I see some solution that implement a C# program invoke a C# "exe" file." It's possible to invoke any exe from a .Net application. But embedding exe into another exe it's a different story...

Author

Commented:
Sorry. I mean some solutions implement a C# program invoke a C#  embeded "exe" file(Import a exe into a c# solution and set it to a embeded resource then invoke it)