3 ms·
The idiomatic way write an uninstaller 1. Clean up whatever you can in the uninstaller. If you're a decent human being this includes the registry, appdata, tem
by alexvitkov 3y ago
The idiomatic way write an uninstaller
1. Clean up whatever you can in the uninstaller. If you're a decent human being this includes the registry, appdata, temp, and a toggle to delete wherever your app spews its config.
The only thing left should be the uninstaller .exe and the directories leading up to it, since Windows doesn't allow you to unlink a exe/dll that's loaded in memory. Your uninstaller should be static linked so it doesn't need to clean up its own .dlls.
2. Figure out how to delete the uninstaller. This can either be some stack smashing butt clenching fuckery, like the guys from the article did or you can be a normal fucking person and just atexit() a batch script in that does
SLEEP 5
RMDIR program_dir /whatever /flags /needed
The SLEEP is to ensure the uninstaller is closed
You can put the batch script in %TEMP% and hope something will clean it up, or if you're feeling extra nice you can set up an action to get it cleaned up at next boot.
After that you're also equipped to write self-deleting malware, which is a far more applicable skill.
- elaus 3y agoThat is pretty much the suggested solution at the end of the article. There, the author also removes the temporary script. The solution really isn't that hard, it might just feel a bit "dirty" (using a scripting language to do some work). But all that "stack smashing butt clenching fuckery" surely is much worse and less stable, so I'm not sure why one would even go that way...
- tmpX7dMeXU 3y agoProgramming language elitism.
- quietbritishjim 3y ago> You can put the batch script in %TEMP% and hope something will clean it up, or if you're feeling extra nice you can set up an action to get it cleaned up at next boot. If you can set an action to get something deleted at next boot why not use that to delete your uninstaller itself, rather than adding an extra layer of indirection?
- alexvitkov 3y agoAs far as I remember the thing you use to delete the file on next boot does not run arbitrary code, but is a special "rename-like" action that you can't use to recursively delete the folder of your program. edit: https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefilea https://learn.microsoft.com/en-us/windows/win32/api/winbase/... It's the MOVEFILE_DELAY_UNTIL_REBOOT flag. Honestly maybe you can call MoveFileA on the entire directory tree you want to delete starting from the .exe and spare yourself the script, I don't see an obvious reason why it wouldn't work.
- deleted 3y ago[deleted]
- xeonmc 3y agoor why not just make the uninstaller a stub executable that copies the real executable into the temp folder and run that instead?
- unnouinceput 3y agoI did that in my first years of creating uninstallers. But I was unhappy with the solution. Too much convolution, extra stuff to take care, etc. So then I was like "why can't I just delete myself at the end of the entire process?". I mean you can definitely unlink yourself (see Unlocker utility) using same API's. Except I started to run into faults. For some reason, on some systems, this was a bust. How I am writing my self-deleting uninstallers nowadays? Very simple. Create a temporary removable drive in memory (see RAMDisk), write the 2nd part of the uninstaller there, then at the end of the process corrupt that disk intentionally. It will "nuke from orbit" and leave no trace.