Jump to content
  • Advertisement
Sign in to follow this  
ehmdjii

how does a software restart itself

This topic is 4550 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

when a software downloads some updates, it may require to restart the application. how is this realized? (not c++ or java specific, but in general) thanks!

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Start a new instance of the software (using shell iirc)

then shut yourself down.

Share this post


Link to post
Share on other sites
yes, but wouldnt that result in the software running twice (for a short time) ?

what if the executable itself requires to be updated?

how can i start the update process after the instance has stopped running?

Share this post


Link to post
Share on other sites
I believe the update program is generally seperate to the actual application, thereby allowing it to update the application and start it when the updates are done.

If its built in you could probably just download a small script that pauses for a few seconds to allow the application time to close, then updates the exe as necessary, before relaunching the applcation once complete.

Share this post


Link to post
Share on other sites
Quote:
Original post by ehmdjii
yes, but wouldnt that result in the software running twice (for a short time) ?

what if the executable itself requires to be updated?

how can i start the update process after the instance has stopped running?


There is a good old method of creating a named Mutex when application starts and destroying it when right before the app exit's. If the app is unable to create the mutex because it already exists - then there is another instance of the app running. I know this isn't a perfect method of not allowing your app to run twice, but it is very handy in your situation.
You can use this mutex in your updater program too, to find out if there is an instance of your program running or not. If not - proceed with update, and then start the app when updated all files. If there is an instance - updater sleeps for a second or two, and then it checks again.

Anyway, that is how i would try to do it.

Good luck.

Share this post


Link to post
Share on other sites
Quote:
Original post by gavco98
I believe the update program is generally seperate to the actual application, thereby allowing it to update the application and start it when the updates are done.


Indeed. When patchers have to update themselves, they usually have to resort to trickery that closes the file they're running from AFAIK or system triggers to do the deed on their behalf. I don't have any of the articles I've skimmed on this bookmarked, so I'd suggest [google] if that's what you're attempting to accomplish.

Share this post


Link to post
Share on other sites
There's a way around being able to update the running application that I use for a program of mine (a MUD client):
  • Program version 1 checks for updates, and finds version 2 is availiable. V1 downloads V2 and extracts it to the temp folder.
  • V1 executes V2 (With CreateProcess()), telling it the directory that V1 is in as a command line argument, and then exits
  • V2 waits a short time for V1 to exit, and then copies itself into the directory passed to it on the command line (V1's directory).
  • V2 now executes the newly copied file which is in V1's old location, but is V2 (Lets call this V2b), passing the location of the temp folder as a command line argument. V2 now exits
  • V2b now executes and deletes V2 from the temp folder (going by the directory passed on the command line)
  • V2b now executes as normal.

    Now the application is running normally in the correct location, and is the latest version.

    Share this post


    Link to post
    Share on other sites
    Sign in to follow this  

    • Advertisement
    ×

    Important Information

    By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

    We are the game development community.

    Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

    Sign me up!