Archive: Can installer update itself?


Can installer update itself?
I'm nearing the completion of an online updater, and one task that would be nice is for the installer to update itself.

I have tried many different ways, such as downloading as a different name, and then renaming as the last task in the installer, but this doesnt seem to work?

Is there an easy way around this? I couldn't find anything in the forums on this topic, and don't want to have to reboot either since the updater is mostly automated.

Thanks!


Couldn't you launch a detached script (i.e don't wait for it to finish) then exit the installer. The launched script (or whatever) pauses for a few seconds then runs the new installer exe?


I'm not quite sure what you mean Ximon.

If I have to run something separate, surely I'd need to delete that too, once I've finished?

What do you mean by a detached script?

Thanks for the help!


Maybe I've got the wrong end of the stick but this is my idea...

- Run your installer
- Download a new file installer version as another filename
- Extract tiny assistant program
- Exec 'tiny assistant program'
- Quit

The tiny program or script or whatever sleeps for a couple of seconds to give the first installer time to quit, deletes the first installer, renames the new one then launches it and that then deletes the tiny assistant program.

It's not very neat I know :(


Sleeping is not a good idea... You better send it $HWNDPARENT as a command line parameter and then it should wait until the owner process of the HWND is terminated. Same for the new installer.


Ah you didn't dismiss the idea outright! Cheers! :D


I can't thank you enough for all your help you guys!!

I did what you suggested Ximon, and it works very well.

I'm not sure what you were talking about Amir, regarding $HWNDPARENT. I presume you mean something about closing the parent window (the one that spawned the helper).

Did you mean to sendmessage or something, to get rid of it, or to detect its existence, if it's still there?

Could you explain in more detail what you mean...perhaps a small example?


Glad I could help.


What I meant is that you can not be sure that after the sleep period the installer would exit. You must somehow detect that it was indeed termintated so you can replace the EXE.

Here is the code needed:
In the updater:
Exec '"$TEMP\helper.exe" $HWNDPARENT'

In the helper:
// Get the command line with GetCommandLine() and get the
// HWNDPARENT from it
DWORD pId;
HANDLE hP;
GetWindowThreadProcessId(hwParent, &pId);
hP = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pId);
WaitForSingleObject(hP, /*time-out interval*/10000);
CloseHandle(hP);


Alternative
You could of course (but this isn't much "safer") just sleep n seconds then try deleting the old .exe and if it fails wait a bit longer upto a maximum by which point you decide that there is a severe problem.


This is kinda what I'm doing Ximon.

I don't know much about C, but my helper is another installer that downloads the new Updater anyway.

I've just discovered UPX, so my installers are now much smaller...that helper is only 25k.

Thanks again guys!