0

I know saving/loading settings from Registry/local file... But is there any way to load some settings and variables from Standalone .exe itself? (not to touch registry or any external file) and to save some settings inside the executable again...

For example, I used variables like this inside filename:

 projectfor_MikeFranklin@mail.com_1991.exe

so, in application, I used regex to catch first and second underscore _ and then got values as variables... So, this was the only method for me, to send the STANDALONE file to other person with my defined variables..

Now I think, if there is a way to write/read such variables into file properties or elsewhere, which will pass when I send file to other persons..

T.Todua
  • 53,146
  • 19
  • 236
  • 237
  • Why not just use hardcoded values or external configuration files? Relying on file name pattern seems rather error prone – Allan S. Hansen Jan 03 '17 at 07:57
  • 1
    @AllanS.Hansen OP wants to override/mutate those variables – nozzleman Jan 03 '17 at 07:58
  • As far as i am concerned, the correct way for this would be using app.config / web.config. I don't know of any way to store mutatable variables inside IL Code – nozzleman Jan 03 '17 at 07:59
  • Per marked duplicate, you can't write to the running .exe. If you want to be able to send a single file, combine an appropriate data file with the .exe in a .zip archive. Then you can send the .zip archive as a single, standalone file. When unpacked into a directory, the data file will be present and usable by the .exe when running. – Peter Duniho Jan 03 '17 at 08:04
  • Firstly, you should get executable file name System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName. Then, you can do whatever on this string. – GSP Jan 03 '17 at 08:27
  • 1
    it may be possible using a combination of self extracting archives + auto run and repacking from the temporary folder and overwriting your original archive. A link that might be useful if it is possible at all http://superuser.com/questions/42788/is-it-possible-to-execute-a-file-after-extraction-from-a-7-zip-self-extracting-a But this is more of a hack than an intended use, if it works at all. – prof1990 Jan 03 '17 at 08:30
  • No Guys, offered solution (to repack and write in 3rd party file) is not wanted at this moment. however, thanks.. – T.Todua Jan 03 '17 at 08:45

0 Answers0