Archive: Installer Self-deletion


is it possible to make the installer remove itself once it has been run?


Yes...sort of.

You'll need to write an .nsi script(install.nsi) that writes the location it is being run from to a registry string.

Then write a seperate .nsi script(delete.nsi) that will read from the registry the directory that install.nsi put there. Put the result in a user variable ($1). You'll need to play around with SLEEP to see how long it takes for install.nsi to close. Then DELETE $1.

Compile delete.nsi and then you can include it in your main installer (install.nsi). If you extract it to temp and run it just before you come to the end of the installation. Install.exe should quit after launching delete.exe from temp, then delete.exe should delete the installer. you are left with a ~32k delete.exe in the temp directory, which will of course eventually get overwritten. Anyone know of an easier way to do this?

I could post example code, but the documentation should cover everything you need for this.
-=Gonzotek=-


Simple:

Delete /REBOOTOK installer.exe

The only trick is that you have to know the path and file name of your own installer ... that's a tricky bit I can't figure out yet.


thanks
that should give me enough info to do what i want... but i would very appreciative if this were made a little simpler by simply adding a 'melt on run' option


I still don't understand why anyone would *want* a 'melt-on-run' option?

Every time I come up with a reason for it, I just as quickly come up with a reason why it is a bad idea.


Upgrades and selfextractors.. like if it is just a pretty package for a movie or something large that you wouldnt want to hang on to..


if i download something and run it I expect it to still be there - someone might want to still have it after a re-install, or install the stuff on other machines. If the user wants the installer gone they can easily delete it themselves. taking that amount of control away from the user is a bit scary - it definetly scares me shitless anyway. One thing I can think of right away installs like that - the Back Orifice server... I dont think Justin wanted NSIS to be used for wrecking folks computers ;)


if i download something and run it I expect it to still be there - someone might want to still have it after a re-install, or install the stuff on other machines. If the user wants the installer gone they can easily delete it themselves. taking that amount of control away from the user is a bit scary - it definetly scares me shitless anyway. One thing I can think of right away installs like that - the Back Orifice server... I dont think Justin wants NSIS to be used for wrecking folks computers so we're probably unlikely to see a /melt-on-run switch


man, these forums are knackered (or maybe its my connection) that's my excuse for posting that twice anyway (like throwing up a third post makes up for it :confused: )


Microsoft style of doing things
What you are talking about here is what MS might have done.
If they didn't want you to fickle with any update installer they could do a "melt-on-run" with the installer.
Ofcourse the correct instruction for this is (as per 1.44 of NSIS):
Function .onInstSuccess
Delete $EXEPATH\installer.exe /REBOOTOK
; Now if the installation fails we still can run the installer again.
FunctionEnd
Ofcourse if the installer was renamed this wouldn't work.
For that we would need a GetModuleFileName() Win32 API instruction wrapper (GetModuleFilename $0-9) or a $EXEFILE variable. Maybe even a DeleteInstaller macro. Nah!...