Im trying to run exes from memory such as outlined in this article. I can run any .net/managed exes quite easily. But I cannot run exes such as notepad or calc.exe. How can I get it so I can also run unmanaged exes?
In the case of running .NET executables from memory, the libraries and CLR itself are doing a lot of heavy lifting for you. For native executables like notepad.exe and calc.exe, you'll have to do a lot of manual work to get it to happen. Basically, you have to act like the Windows loader.
There's probably pages of caveats here, but this in-depth article has the steps you need to load a PE into memory and do the correct rebasing and fixups. Then, you should be able to find the entry point (like in the article) and run it.
If you're really just wanting to run notepad.exe and calc.exe, the easiest way, of course, would be to use Process.Start
and run them off disk. Otherwise, if you have an executable embedded as a resource in your process, then the next easiest way would be to just write the contents out to disk in a temporary location (see Path.GetTempFileName
) and then execute it from there.
Use [Process.Start()][1]
(or another overload), and let the O/S do the loading into memory.