0

I am developing a small project in C#. I have used costura-fody to embed all dependencies into the executable file. I want to embed some mutable content(some settings)in the app as well. So my program would be completely portable.

What I think might work:

I think if the exe copies itself to a different location, starts that executable, and terminates itself, the new exe should be able to make changes to the main exe file. After that it can start the main exe and terminate itself, and the main exe will delete the temporary exe file created. That way I can "logically" make changes in an exe file.

Problem:

I don't know how to do it. I do not know how can I save the settings in the existing exe. I know this is possible ( maybe with a different approach ), because I have seen a program do this. SelfNote does this

Please can anyone help me, how can save data in an existing exe file, and then access it later on, while running that exe ???

Damini Suthar
  • 1,470
  • 2
  • 14
  • 43
mrid
  • 5,782
  • 5
  • 28
  • 71
  • 4
    **This is a terrible idea.** – erikvimz Dec 20 '17 at 13:25
  • Sounds like a terrible idea, but I guess [Alternate data streams (ADS)](https://en.wikipedia.org/wiki/NTFS#Alternate_data_streams_(ADS)) would work for something like that. – Manfred Radlwimmer Dec 20 '17 at 13:25
  • 2
    The flaw here is the idea to distribute software as single exe-file. Distribute it as exe-file plus settings-file and you are fine. *Portable* software is rather a package than a single exe. – Sinatr Dec 20 '17 at 13:27
  • @Eric I know that exe is immutable. But I want to know how SelfNote handles it. – mrid Dec 20 '17 at 13:29
  • I used to work for a company where one of the products had an installer that could download and install a new version of said product. After the initial installation, the product would check for updates regularly (based on a timer) and if there was an update available it would start the installer and termintate. Then the installer would download a new version and activate it. I didn't write the installer so I have no idea how it was done, just that it's possible even on .net 3.5 compact version. – Zohar Peled Dec 20 '17 at 13:29
  • @ManfredRadlwimmer ADS would work fine as long as the program is in a particular directory on the system. It won't work if I move the exe to another system – mrid Dec 20 '17 at 13:30
  • @mrid Oh you wanted to keep the config while distributing? Honestly you should re-think that approach. The only thing you need to have your application portable is keep all files (dlls, settings, data, etc.) in a common directory (no `%User%`, no registry, etc.). – Manfred Radlwimmer Dec 20 '17 at 13:31
  • 2
    [Click](https://stackoverflow.com/q/26123494/1997232), [click](https://stackoverflow.com/q/13174425/1997232), should be more. – Sinatr Dec 20 '17 at 13:34

0 Answers0