Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt 4.8.4 way to change the running excusable name in runtime



  • Hey
    i have Qt c++ app that on each start is checking if there is new executable update file
    and if there is it downloading it, the problem is how can i change the name of the old executble to for example :
    foo_tmp.exe
    and the new executable
    to :
    foo.exe
    or in runtime or on closing or on start something


  • Lifetime Qt Champion

    Hi,

    On windows you can't change/modify/etc... a running application.

    One way to do that is to have an application launcher, the launcher checks if a new version is available, downloads it, performs whatever is needed and then starts the application.

    Hope it helps



  • the main exe is the application launcher , is there any other method to start the app exe ? not using cmd or script


  • Lifetime Qt Champion

    AFAIK no, but you can write your own launcher executable that does that: check if there is something and if there is not, start your application. That's what firefox does for example.



  • so i will hold 2 excusable , and the launcher will be my main exe
    when starting it will check if there is update ,
    if yes download and rename
    if no start the main app
    right ?
    is there any other way ?


  • Lifetime Qt Champion

    Right.
    Like I said before you can't modify the file of a running application on windows.



  • looks like it can ( didnit try it )
    "Your text to link here...":http://stackoverflow.com/questions/9162969/how-can-a-c-binary-replace-itself


  • Lifetime Qt Champion

    Then you can try using QFile::rename



  • [quote author="umen242" date="1376053506"]Hey
    i have Qt c++ app that on each start is checking if there is new executable update file
    and if there is it downloading it, the problem is how can i change the name of the old executble to for example :
    foo_tmp.exe
    and the new executable
    to :
    foo.exe
    or in runtime or on closing or on start something [/quote]

    Typically you could go like this:

    1. Have the "main" EXE check for updates

    2. If update is available, download "updater.exe" to the system TEMP folder

    3. Let the "main" EXE start the "updater.exe" it just downloaded (from TEMP folder) and make the "main" EXE terminate itself right after that

    4. Now the "updater.exe" can install the update and also replace the "main" EXE with a new version - because "main" EXE is not running anymore

    I'd recommend to create "updater.exe" with "NSIS":http://nsis.sourceforge.net/Main_Page

    --

    How does "updater.exe" know where "main" EXE is located?

    Just have the "main" EXE pass its own path to the "update.exe" via command-line parameter.

    --

    How to clean up the "updater.exe" from TEMP folder?

    Obviously the "updater.exe" can not delete itself. But there is a function in the Win32 API which allows files to be scheduled for deletion on next reboot.

    "MoveFileEx":http://tinyurl.com/movefilex

    (See MOVEFILE_DELAY_UNTIL_REBOOT flag for details)


  • Lifetime Qt Champion

    Interesting alternative ! Thanks


Log in to reply