Chris wrote:
You could also have the script create a bat file via FileAppend that the script launches right before it exits. Such a bat file could delete the script and probably itself.
That would be the best, write a batch file, but this works...
Code:
; DeleteSelf.ahk, compile to see it really work (it always worked as .ahk)
;
msgbox, 4, , Delete %a_scriptname%?
IfMsgBox, No, exit
;FileDelete, %a_scriptname% ; when I tried this it didn't work (for .exe)
Run, %comspec% /c del "%a_scriptname%"
exit ; when I don't exit here, it don't work
if errorlevel <> 0
msgbox, 16, , Error! File %a_scriptname% not deleted. Errorlevel: %errorlevel%
else
msgbox, File %a_scriptname% was deleted. Errorlevel: %errorlevel%
...I had the errorlevel checks in initially for the FileDelete, then left em for the Run, but when I put exit in, it made the .exe quit before the del command finished...a race condition, but it works.