Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 630271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:50:14+00:00 2026-05-13T19:50:14+00:00

Is it possible to execute an exe file that is included in the project

  • 0

Is it possible to execute an exe file that is included in the project as a resource? Can I fetch the file as a byte array and execute it in memory?

I don’t want to write the file to a temporary location and execute it there. I’m searching for a solution where I can execute it in memory. (It’s not a .NET assembly.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:50:15+00:00Added an answer on May 13, 2026 at 7:50 pm

    It’s quite possible – I’ve done it myself – but it’s fiddly and more so from managed code. There’s no .NET API for it, nor is there a native API for it which you can PInvoke. So you’ll have to fenagle the load by hand, which will require some knowledge of the PE (Portable Executable) file format used for modules such as DLLs and EXEs – http://msdn.microsoft.com/en-us/magazine/cc301805.aspx. There’ll be a lot of pointer manipulation (mandating use of unsafe {} blocks) and PInvoke.

    First load the PE file into memory (or use MapViewOfFile). A PE file is internally made up of different sections containing code, data or resources. The offsets of each section in the file don’t always match intended in-memory offsets, so some minor adjustments are required.

    Every PE file assumes it’ll be loaded at a certain base address in virtual memory. Unless you can ensure this you’ll need to walk the PE file’s relocation table to adjust pointers accordingly.

    Each PE file also has an import table listing which other DLLs’ functions it wants to call. You’ll need to walk this table and call LoadLibrary() / GetProcAddress() to fill in each import.

    Next, memory protection needs to be set correctly for each section. Each section’s header notes the protection it wants, so it’s just a matter of calling VirtualProtect() for each section with the correct flags. At a minimum you’ll need to VirtualProtect the loaded module with PAGE_EXECUTE_READWRITE or you’re unlikely to be able to execute any code.

    Lastly for a DLL you need to call its entry point, whose address can be found in the PE header; you can then freely call exported functions.

    Since you want to run an EXE, you’ve got some additional headaches. You can just spin up a new thread and call the EXE’s entry point from it, but many EXE’s may get upset since the process is set up for you, not the EXE. It also may well kill your process when it tries to exit. You might want to spawn a new process therefore – perhaps another copy of your main EXE with special arguments to tell it it’s going to run some different code – in which case you’d have to fenagle the EXE into its memory space. You’d probably want to do most of the above work in the new process, not the old. You could either create a named pipe and send the data across from one EXE to the other, or allocate a named shared memory area with MapViewOfFile. Of course the EXE may still get upset since the process its running in still isn’t its own.

    All in all its far easier just to write to a temporary file and then use Process.Start().

    If you still want to do it the hard way, take a look at this example in unmanaged code: http://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/. This doesn’t cover executables, just DLLs, but if the code therein doesn’t scare you you’d be fine extending the process to cover executables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does it possible to execute php file and store its output into some variable?
Is it possible to execute a specific sub in a vbs file from a
Given a string location and string file name, is it possible to execute a
When you create a Windwows Service, you end up with a .exe file that
Can you execute a VBS file as a screen saver? I have managed to
I want to execute a external .exe program from within java. The .exe is
Is it possible to execute an SPDataSource object query in a console app for
How is it possible to execute a direct SQL command to an ADO.NET connected
Is it possible to execute the two update queries in phpmyadmin together? Like wise
Is it possible to execute store procedure like a table for SELECT operator (MS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.