Can you embed files into exe, and update them with each use?


Can you embed files into exe, and update them with each use?
I'm trying to make an application which to manage information about several providers.
Target system is windows and I'll be coding with c++.
The users are not expected to be handy on anything related to computers, so I want to make it as fool-proof as possible. Right now my objective is to distribute only an executable, which should store all the information they introduce in there.
Each user stores information of their own providers, so I don't need the aplication to share the data with other instances. They do upload the information into a preexisting system via csv, but I can handle that easily.
I expect them to introduce new information at least once a month, so I need to update the information embedded. Is that even possible? Making a portable exe and update its information? So far the only portable apps I've seen which allow saving some personification do so by making you drag files along with your exe.
I try to avoid SQL to avoid compatibility problems (for my own applications I use external TXTs and parse the data), but if you people tell me it's the only way, I'll use sql.
I've seen several other questions about embedding files, but it seems all of them are constants. My files need to be updatable
Thanks in advance!
Edit: Thanks everyone for your comments. I've understood that what I want is not worth the problems it'd create. I'll store the data separatedly and make an effort so my coworkers understand what's the difference between an executable and it's data (just like explaining the internet to your grandma's grandma...)
Can you not simply make an installer that copies the files into place? That's a pretty standard installation procedure no one should have trouble with.
– Baum mit Augen
2 days ago
Storing user data in external files is the simplest and preferred solution. Just put them all in a single folder to make it easy for the user to find them. Don't try to embed the data inside the executable itself, the OS won't allow it.
– Remy Lebeau
2 days ago
"I try to avoid SQL to avoid compatibility problems..." How so? Depending on your use-case SQL might be a nice fit that could reduce compatibility problems. I'm unsure about your data based on above, but it sounds like SQLite might be a solution here. In any case, I would (like everyone else here) strongly advise against trying to modify your executable!
– ravnsgaard
2 days ago
What if two users log into the same machine? Per-user data needs to be stored in per-user locations. The executable image isn't.
– IInspectable
2 days ago
2 Answers
2
While I wouldn't go as far as to say that it's impossible, it will definitely be neither simple nor pretty nor something anyone should ever recommend doing.
The basic problem is: While your .exe is running, the .exe file is mapped into memory and cannot be modified. Now, one thing you could do is have your .exe, when it's started, create a temporary copy of itself somewhere, start that one, tell the new process where the original image is located (e.g., via commandline arguments), and then have the original exit. That temporary copy could then modify the original image. To put data into your .exe, you can either use Resources, or manually modify the PE image, e.g., using a special section created inside the image to hold your data. You can also simply append arbitrary data at the end of an .exe file without corrupting it.
However, I would like to stress again that I do not recommend actually doing stuff like that. I would simply store data in separate files. If your users are familiar with Excel, then they should be familiar with the idea that data is stored in files…
Have a look at UpdateResource(). A rather old but still useful article about it can be found over at CodeProject: How to manipulate raw resources (RT_RCDATA) using UpdateResource().
You cannot update resources linked into an executable image that's currently executing.
– IInspectable
2 days ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
How difficult is it to require the user to unzip a zipped file containing both executable and some other files...?
– Passer By
2 days ago