Save data in executable

Artur Carvalho picture Artur Carvalho · Sep 7, 2010 · Viewed 8.6k times · Source

I have a portable executable that saves data to a file in the same folder as the executable. Is there any way that I can save data into the executable itself when I close the app?

This maybe weird, but taking the data with me and only have one file for the exe and data would be great.

Would prefer if this was made with C#, but is not a requisite.

Answer

KeithS picture KeithS · Sep 7, 2010

You cannot modify your own EXE to contain stored data in anything approaching an elegant or compact way. First off, the OS obtains a lock on the EXE file while the application contained within is being run. Second, an EXE comes pre-compiled (into MSIL at least), and modification of the file's source data usually requires recompilation to reset various pointers to code handles, or else a SERIOUS knowledge on a very esoteric level about what you're doing to the file.

The generally-accepted methods are the application config file, a resource file, or some custom file you create/read/modify at runtime, like you're doing now. Two files for an application should not be cause for concern