- 전체
- Native Apps
- WinJS App
- C# Apps
- XAML
- VB.net
- VisualC.net
- C++
- MFC
- visual studio mobile app dev
- Azure ms cloud service
- Asp.net
- 인공지능 (AI)
- wpf
- UWP
- MAUI
- asp.net
C++ Load an EXE File and Run It from Memory
2017.07.01 19:06
Load an EXE File and Run It from Memory

Gianni Marzaloni (ZofM), 24 Apr 2006
Simple application to load an EXE file and run it from memory (only for .NET compiled files)
Introduction
This example shows how to load an application and run it from the memory system. After the application load, you can use it without the source EXE file (usually blocked from the system). This is useful when you don't need to have the source EXE file on HDD (e.g. on a USB key).
Using the Code
This example is divided into two simple steps:
- The binary reading of the EXE file
- Its loading into the Assembly cache of the read result
First Step
Load the EXE file in one stream and read it as an array of bytes:
Hide Copy Code
// read the bytes from the application EXE file
FileStream fs = new FileStream(filePath, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
byte[] bin = br.ReadBytes(Convert.ToInt32(fs.Length));
fs.Close();
br.Close();
Using the FileStream class, it is possible to open the EXE file (location indicated in the filePath variable), read and close it to release resources.
Second Step
Use the Assembly.Load method to load the EXE file (as array of bytes) into the Assembly cache:
Hide Copy Code
// load the bytes into Assembly
Assembly a = Assembly.Load(bin);
Now we can try to find the entry point of the application:
Hide Copy Code
// search for the Entry Point
MethodInfo method = a.EntryPoint;
if (method != null) {
...
}
If an entry point is found, is possible to create an instance of the application Main method and invoke it from our application launcher:
Hide Copy Code
// create an instance of the Startup form Main method
object o = a.CreateInstance(method.Name);
// invoke the application starting point
method.Invoke(o, null);
If all will be ok, the called application will start without using the source EXE file (try to move it to check).
In the demo project zip file, I put a simple application launches one EXE file found in the same folder of the launcher EXE. If there are more than one files, a request file Form starts to ask the user which file to select from the folder.
NOTE: Pay attention to the Application.SetCompatibleTextRenderingDefault method of the called application. Visual Studio 2005 applies this line in the Main method (located inside the Program.cs file) to use the new GDI+ library in our applications, but it will throw an exception because it must be called before the first IWin32Window object is created.
History
- 24th April, 2006: Initial post
License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
[출처] https://www.codeproject.com/Articles/13897/Load-an-EXE-File-and-Run-It-from-Memory
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
댓글 0
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
|---|---|---|---|---|
| 5 | 윈도우 wcript.shell | 졸리운_곰 | 2020.09.10 | 296 |
| 4 | WSH(WIndows Script Hosting) 정리 | 졸리운_곰 | 2020.09.10 | 946 |
| 3 |
VB로 웹페이지 읽어오기 - 웹 스크랩
| 졸리운_곰 | 2020.01.03 | 324 |
| 2 | MetaWeblogAPI VisualBasic .NET 코드 샘플 | 졸리운_곰 | 2019.02.08 | 440 |
| 1 |
An Application Framework for Editing Objects at Run Time in VB.NET
| 졸리운_곰 | 2017.07.01 | 1220 |

