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")
In Visual Studio, select File > Open > Project. In the Open Project dialog box, select All Project Files, if not already selected, in the dropdown next to File name. Navigate to the .exe file, select it, and select Open. The file appears in a new, temporary Visual Studio solution.
To build your program and create teh executable file choose Build My Project.exe from the Build menu - "My Project" represents teh name you chose for your project and the extension ".exe" is used to designate that the file being created will be an executable file.
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.
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)
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With