C ++ automatically updates to the new version

I searched for a good solution for 3 days, but so far I have not been able to find it. My situation:

The client has an installed application (C ++, console application). The application at startup checks its version number on the server and returns or is updated, or that it should download the new version.

If he needs to download a new version, I would like to download a new script using Curl for the name say: Application2.exe

However, I want it to replace the old Application.exe , which caused the new version to load.

My solution was: Application.exe loads Application2.exe . When loading, it should run Updater.exe , which sleeps, let them say 5 seconds. During these 5 seconds (or any other period of time that is best suited). During these 5 seconds, Application.exe has time to shut down and after 5 seconds Updater.exe replaces Application.exe with Application2.exe .

Now the update is completed, and the client has the latest version installed.

Is this possible with respect to system lock files, etc.?

+4
source share
1 answer

The good news is, you can rename files opened in Windows (executable files and DLLs). Lock prevents you from deleting files, and not renaming them.

  • Rename the currently running program to Application_old.exeat the time of its launch.
  • Write the downloaded program to Application.exe
  • Launch new Application.exe
  • Close the old one.
  • Uninstall the old version using the new executable program.

Thus, after the update, an automatic restart will be performed. I do it myself all the time.

+5
source

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


All Articles