Update the program by writing to the executable file

I am writing a C ++ program that sooner or later will need to be updated. I want this to require as little user interaction as possible because the program runs constantly in the background and never ends. I know that under normal circumstances you cannot write to a file that is running, so this is my question: is it possible for the application to modify itself without starting another executable file and not allowing it to be done? I cannot have more than one file.

+3
source share
3 answers

Most programs that use auto-update features use a different executable file to execute to avoid this problem.

However, I see a somewhat simple solution:

  • old programuploads new programto a temporary location
  • old programstarts new program(possibly with a special parameter) and exits itself
  • new programcopies itself on top old program(it should be normal for the running program to read itself if it is not open for writing)
  • new programstarts new program (copy)with a special argument and then exits itself
  • new program (copy)deletes new programand resumes normal operations

Is this clear enough? :)

+4
source

, , , . , , , .

0

, .NET/Java, . ++ - . , . , - , LLVM, .

0

Source: https://habr.com/ru/post/1757158/


All Articles