I am writing a c++ program which sooner or later will need to be updated. I want this to require as little interaction with the user as possible since the program runs constantly in the background and never terminates. I know that under normal circumstances, you can’t write to a file that’s being executed, so this is my question: is it possible for an application to modify itself without just running another executable and letting that one take over? I can’t have more than one file.
Share
Most programs using auto-update features use another executable to take over execution in order to avoid that problem.
However I see a somewhat simple solution:
old programdownloadsnew programinto a temporary locationold programstartsnew program(possibly with a special parameter) and terminates itselfnew programcopies itself overold program(it should be ok for a running program to read itself, as long as it doesn’t open itself for writing)new programrunsnew program (copy)with a special argument, and then terminates itselfnew program (copy)deletesnew programand resumes normal operationsIs it clear enough ? 🙂