I put a executable file into my project resources and set its build action to "Embedded resource". When I request this resource I get an array of byte. How can I execute this resource as if it is a executable file? If this is possible I prefer a solution without having to write the byte array into a executable file and execute this file.
Asked
Active
Viewed 149 times
-1
-
1See http://stackoverflow.com/a/2977241/870604 – ken2k Dec 24 '13 at 13:46
-
Possible in principle (at least for dlls which usually include relocation info), but annoying in practice. One of the biggest difficulties is that if you don't load an executable at its base address and that executable doesn't consist of position independent code, you need to relocate it. There are code samples for doing relocation yourself, but it isn't trivial. – CodesInChaos Dec 24 '13 at 13:48
1 Answers
2
For managed assemblies, this is easy to do. So I assume that you are referring to unmanaged executables. There is no officially supported way to create an unmanaged process from a file held in memory. The only supported way to do this is to write it to a file and use, CreateProcess
or similar.
Having said that, if you are prepared to break the rules, there are plenty of libraries and code samples around that will trick Windows into creating a process from an executable image held in memory. Do be prepared for anti-malware programs to take an interest in your program once it starts doing this.

David Heffernan
- 601,492
- 42
- 1,072
- 1,490