Archive: Self deleting installer


Self deleting installer
Hi,

feature suggestion for NSIS scripting language:

add some command like

"SetDeleteOnQuit true"

This command should set some flag and the installer should delete itself when terminating (caused e.g. by Quit,Abort...).

I know this can be done manually using some tricks and I know that Uninstallers do something similar by default (when not using special arg ?=). But it could be useful in many situations. E.g. RegTool.bin (library.nsh) is compiled using a two-step installer so in fact that binary is an uninstaller to have the Delete-on-quit feature. Could be done the easy way then.

The command should be runtime (not compile-time).

For installers the value should be "false" by default, of course. I know there is some issue with current uninstallers: I guess they move themself to TEMP while loading. So I would let the behaviour of uninstallers as it is (besides SetDeleteOnQuit should delete $INSTDIR/uninstall.exe at the end).


You probably can combine 4.7.2.1.9 .onUserAbort and SelfDel plug-in


The command can't be a runtime command because this is done before any code is run. Uninstallers don't really delete themselves, they only copy themselves to the TEMP directory and set that copy to be deleted on reboot. The copy can then delete the original, if it wants to.

It can be made a compile time command which will simply set the uninstaller flag to the generated installer. It's just one simple flag set in the firstheader structure, called FH_FLAGS_UNINSTALL.


Hi kichik,

compile time would help with those installer-in-installer packages like regtool.bin. But that's not what I want. Are you sure that Uninstallers do not delete themself. Using MoveFile(Ex) "/deleteonreboot" would be an easy solution (one could do manually), but IIRC Uninstaller does some self-delete trick like that one mentioned on the site mentioned in the selfdel plug-in (catch22...) But you're the expert so you'll know what you write.

Why am I looking for a run-time command? I could use this to create dynamic installers which "update" themself (downloading a installer package and executing it). Currently I execute the downloaded installer package using ExecWait (has some other advantage but needs special handling for Mutex).


Uninstallers only copy themselves to the TEMP directory and execute from. You don't have to use `Delete $INSTDIR\uninstall.exe`, so it doesn't really have to delete itself. You can do the same using CopyFiles, Exec and Delete /REBOOTOK.


If you are happy with deleting after a reboot, then surely Delete /rebootok "$EXEDIR\setup.exe" will work (unless there is something I am missing).

You should get the installer file name first however, using this function:
http://nsis.sourceforge.net/Get_installer_filename

-Stu


Thanks Stu,

but I'm not "happy" with this. (Hey, this seems to easy... we're professionals, eh?) ;-)

Please see my self-del runtime command suggestion as "nice to have". Maybe it can be done easily. I think this would be a valuable function making installers even more powerful. I currently work around using ExecWAIT so I can delete the sub-installer after it finishes.

Again: Is this (current uninstaller behaviour) just delete-on-reboot? My guess is: no.


It's not only delete-on-reboot, it's copy to TEMP, optionally delete original immediately and delete copy on reboot. Please add the request to the feature request tracker.


Well I could create a Wiki page for this with a small executable download and macro to delete the installer...

It would have to be called .onGUIEnd or whatever though.

-Stu


Although it is not done purely in NSIS script, you could also use the InstStub.exe/ExitStub.exe component within the CABSetup suite/plugin to run the (un)installer and have it deleted afterward. No reboots are required.

This was one of the ideas used within that suite to handle the original installer not being available because the source media changed; copy the installer to the TEMP directory and have it removed automatically when it completes.

For the uninstaller, it would mean leaving another file (other than than the uninstaller) on the target computer, but once executed, both files (InstStub and the uninstaller) would be deleted.

Duncan


Another solution: make a wrapper for your exe that extracts the installer to the pluginsdir, then use exewait to run it. The installer is deleted when the wrapper has finished waiting for the installer to finish (I have done the same thing on one of my installers).