1

I have an existing EXE and DLL file (both unmanaged) that I'd ideally like to embed in my C# app and execute at runtime of the C# app. The EXE, when executed normally via command-line or Explorer, requires the DLL to be in the same directory as the EXE. How would I be able to:

1) Embed the EXE and DLL in my app and execute them via C# code?
2) Make sure that the EXE will be able to access its dependent DLL file?

Thanks!

Mark LeMoine
  • 4,478
  • 3
  • 31
  • 52
  • 2
    That's what Setup.exe does. It can do lots more, like making sure they end up in a proper place that doesn't scare either the user or the malware scanner. – Hans Passant Dec 30 '10 at 19:23
  • Hans has a great point, for a .Net application I designed we used a hack to load color cursors by streaming an embedded resource to a temp file and then loading from the file. On some systems the end point protection went haywire as our application loaded. Each customer had to add exception rules to their end point protection for the application (it created a support nightmare). Just keep this in mind when you are considering this design. – pstrjds Dec 30 '10 at 19:26
  • What is your ultimate goal - is it just to carry the EXE and DLL with your app (why not just include them to installer then?) or hide them from the user or ... ? – Eugene Mayevski 'Callback Dec 30 '10 at 20:13
  • @Eugene My goal is to hide it from the user, or rather, run it for them with them needing to do it manually. – Mark LeMoine Dec 31 '10 at 02:58
  • "run for them" and "hide from them" are two orthogonal purposes. For "just running" you can add the files to installation package and install them. Or you can add the files to resources , extract them to the temporary folder and run from there. If you want to *hide*, then it's a different story - you can't unpack them to the disk and the task becomes a bit more complicated. – Eugene Mayevski 'Callback Dec 31 '10 at 07:15
  • as to how to get it done, here is a link on SO http://stackoverflow.com/questions/798655/embedding-an-external-executable-inside-a-c-sharp-program/ – nawfal May 15 '12 at 12:12

3 Answers3

3

Put them in Project embedded Resources.
When your program runs extract them from Resources, copy into known location and execute via Process.Start

Sergey Mirvoda
  • 3,209
  • 2
  • 26
  • 30
3

Add the files as embedded resources. You can then export them to wherever you like in your code. Use the System.Diagnostics.Process class to run it.

Edit: You may also want to cache the location name so that you can delete the files when your C# application exits (if you want to be nice and cleanup after yourself that is)

pstrjds
  • 16,840
  • 6
  • 52
  • 61
1

There is .NETZ which I have used once successfully. It seems that the tool also supports native unmanaged DLLs to some degree.

Maybe it helps as a pointer to give you some ideas for your actual desired solution.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291