2

I have read allot of posts on saving settings but none actually get to the heart of what I'm trying to do. I have created a configuration application for a 3rd party application the settings of which need to change from site to site. I'm trying to find a way to store these settings inside the executable without having to compile hard coded settings into it. this will let the end user edit the settings if for instance they need to change a name or IP address in the program.

I need to keep the executable as an EXE only downloadable application, all of the solutions I can find consist of external files that won't be downloadable. Is this even possible?

S Chase
  • 43
  • 1
  • 10
  • The answers to [this question](http://stackoverflow.com/questions/6545858/is-it-possible-to-add-remove-change-an-embedded-resource-in-net-dll) may interest you. That's probably the closest thing you're going to find to what you are trying to do, but it seems unlikely that a process could do that to its own exe file while it is running. – Steven Doggart Sep 23 '13 at 16:56
  • Why not use some of the environmental storage available? Isolated Storage - http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.aspx, the Registry, or somewhere else in the file system? – StingyJack Sep 23 '13 at 16:58
  • 1
    Do you mean you want to store the settings inside the THIRD PARTY executable? How does storing them inside any executable make them easier to edit? If they download a fix, update or new version wont all their old settings get lost? – Ňɏssa Pøngjǣrdenlarp Sep 23 '13 at 17:01
  • I'm trying to store the settings I'm going to change inside my executable, my application will edit the configurations files for the 3rd party application fine now. the reason I want to store this information inside my exe file is so I can distribute it as downloadable content from the internet and the user will not have to change anything unless there has been a configuration change. – S Chase Sep 23 '13 at 18:57
  • You can't do this. You talking of embedding something into EXE - you can do this. But once done you can't change it. I imagine, your client wants you to provide signed assembly. Assembly, no one can temper with. The public key is generated from everything you have inside. Now, if you change things, your public key is no longer valid. What you can do is to create custom config section handler and let your client edit the config file. – T.S. Sep 23 '13 at 19:45
  • Thanks guys, I was afraid the answer would be "No, it can't be done". I suppose I'll have to compile for each customer to have their own config file and train the other techs to edit the settings and compile for future customers, rather than just telling them to modify the settings in the compiled application and save it to the server for download. – S Chase Sep 23 '13 at 20:18
  • It very much sounds to me like you have 2 things perhaps at cross purposes. You said you `let the end user edit the settings` which strongly implies an external file. But you also want some(?) settings to come as DLC from you. Are you in fact talking about 2 sets of settings? In that case, cant the DLC be some sort of settings file? If you would let loose of the HOW (in exe) and give some detail on the WHAT, someone might have an answer...like a serialized data file, maybe. – Ňɏssa Pøngjǣrdenlarp Sep 23 '13 at 23:25

2 Answers2

2

I don't believe .Net will allow you to do it exactly the way you want. While running, the .Exe will be locked for write access. Even if it weren't, the .Net runtime validates the IL signature before just-in-time compiling, and I expect this would break that validating.

It's sad. I've often wished for the same ability. Just let me append my data to the end of the .exe! But it's just not something Windows supports.

Instead, have the program create a settings file on first run. This file can live in the %AppData% special folder, so if the user downloads the .exe and saves it to their desktop, there won't be an unexplained file there.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
0

Use registry setting.

This does not require you to include another file and it saves the setting per user.

But, you must create a section of your application for changing the configuration. The user should NOT edit the registry directly but you should provide an interface within your application that allows them to view/edit the changes.

Steve
  • 5,585
  • 2
  • 18
  • 32
  • The point was that I need to distribute the file with the settings intact to a system that does not have the settings. Saving the settings to the distribution server registry will do no good. – S Chase Sep 23 '13 at 20:28
  • If you want the setting to be part of the EXE, hardcode the values. If you want the user to be able to update the setting, save them somewhere like the registry or a file in the apps path. If you need the user to be able to update the setting and send the exe to someone else in a single exe, you have to allow the user to COMPILE the exe so they need source code and visual studio. Is there something I missed that you need to do? – Steve Sep 23 '13 at 22:39
  • no that's the one and the source of the problem. >"If you need the user to be able to update the setting and send the exe to someone else in a single exe, you have to allow the user to COMPILE the exe so they need source code and visual studio." I was just not wanting to resort to hardcoding into the compile. – S Chase Sep 24 '13 at 20:15