tags:

views:

483

answers:

3

I know that is strange situation, but I need to embed an EXE file (or the assembly code) into my project, so it can be started only by the application (it can't create the EXE in the filesystem and start it)...

Is it possible?

Edit:

It's not a .NET EXE. Anyway I added the Test.exe file as a resource to my project and I did this

   Dim exestr As Stream = Nothing
   Dim a As Assembly = Assembly.GetExecutingAssembly
   exestr = a.GetManifestResourceStream("Test.exe")  
+1  A: 

If the EXE is a .Net assembly, you can embed the compiled binary in your (outer) program, load it using Assembly.Load(byte[]). EDIT: Since it isn't, you can't.

After loading the assembly, you can call functions from the inner assembly (such as the Main method) like any other assembly, or you can write AppDomain.CurrentDomain.ExecuteAssembly(innerAssembly.FullName).

SLaks
updated the first post... the exe is not .Net exe..
Marcx
I'll keep this answer for reference.
SLaks
+1 for the useful info.
Si
ok thanks.. I didn't read the edit before..
Marcx
+2  A: 

Not possible. This was a core design decision made by Dave Cutler and co when they designed Windows NT. A process must be backed by a file on the file system. Windows uses a memory mapped file to map the code of the process to virtual memory. This is not different for a .NET program, even though a lot of its code gets JIT compiled to memory. The assembly that contains the IL gets mapped the same way.

Good for more than just efficient operating system operation, users and virus scanners really dislike executable code popping out of nowhere.

Hans Passant
+1  A: 

I'm thinking create a RAM disk, write your exe file/s to it from your .NET resource file, and execute the file there. Nothing touches physical disk.

I don't have a link for a programmable RAM disk API but you can likely find something to manipulate from your program. The other benefit is virus scanners can still acknowledge it for security.

Also I'm thinking if your app is running on disk then there's no good reason why the executable in question can't be on disk too. If you're piping it in over the network (downloading) it or something, then save to disk first and erase it when done execution.

John K
thank you, I'll try that, hoping works...Anyway I don't want to write and open file because users shouldn't copy the second exe and starts it when they want.
Marcx
Was it a RAM disk solution in the end? Just curious. If so what software did you use to implement it?
John K