Suppose you are working on an application - which
needs to extract another application on runtime. How to achieve the
We can start with the steps below:
Step 1: Create a new Console
Step 2: Embed an exe file
For this - right click on the solution explorer
window and choose "Add existing item"
In the appearing dialog box - type
For convenience I am using the registry editor
utility of windows.
(note: if your windows folder is in different drive
you have to change the above path)
Now you can see the file added to solution
Choose the properties of file and change the Build
Action property to Embedded Resource.
Now build your project - if successful you
are ready with an exe embedded.
Step 3: Get the embedded
Now our goal is to save the embedded exe in runtime
to the same application folder. For achieving this we have to first get the
embedded name of the exe file.
The embedded name of the resource file would be in
the format ApplicationNameSpace.ResourceName.
In our case it is:
You can use the method
to get all the resource names in the
Step 4: Save the embedded
In this final step we are retrieving the bytes of
assembly and saving into a file stream. For this we are using Stream,
The code is given below:
Stream stream =
FileStream fileStream = new FileStream("new.exe",
for (int i = 0; i < stream.Length;
We can see in the output folder that the
new.exe is created