Hey guys, thanks for this thread. Very helpful.
I am doing my own installer in AHK, and reached the stage where my Uninstall.exe needs to delete itself.
The Comspec /c del trick works nicely assuming your exit the self-deleting exe as soon as you call the comspec /c del.
It is similar to how windows behaves when you try to delete a file in use. It will give you a couple of grace seconds to close it, before it jumps with an error that the "file may be in use"
Also know, that when I searched google for "exe file delete itself" - this thread came the first.
EDIT:
Addition, to those who also want to delete the folder where the file resides.
The trick is to call the batch file with a working directory other than the one the file is in, otherwise, the directory will be considered "in use"
Code:
FileDelete %A_Temp%\uninst.bat
FileAppend del "%Filename%"`n, %A_Temp%\uninst.bat
FileAppend rmdir "%Folder%"`n, %A_Temp%\uninst.bat
Run %Comspec% /c %A_Temp%\uninst.bat, %A_Temp%,HIDE
_________________
Sector-Seven - Freeware tools built with AutoHotkey