Code archives/File Utilities/Self-Destructing .exe

This code has been declared by its author to be Public Domain code.

Download source code

Self-Destructing .exe by Subirenihil
(Posted 20 years ago)
Be sure to add the proper lines to shell32.decls

Compile into an empty folder, then run the compiled version to see it self-destruct.

Not sure what would happen if you try to run by just hitting "F5" in the editor - could be very bad (as in deleting part of blitz).
;Compile in its own folder as "Self-Destruct.exe"
;Run the compiled version and it will delete itself
;
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;!! DO NOT RUN FROM WITHIN BLITZ !!
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

;The following lines must be in shell32.decls
;   .lib "shell32.dll"
;   ShellExecute%(hwnd%,Operation$,File$,Parameters$,Directory$,ShowCmd%):"ShellExecuteA"

Graphics 400,300,0,2
SetBuffer FrontBuffer()

SelfDestruct
Text 200,150,"Press any key to self destruct...",1,1
WaitKey
End

Function SelfDestruct()
	dir$=SystemProperty("appdir")
	If Right$(dir$,1)<>"\" Then dir$=dir$+"\"

	tempdir$=SystemProperty("tempdir")
	If Right$(tempdir$,1)<>"\" Then tempdir$=tempdir$+"\"
	
	file$=dir$+"Self-Destruct.exe"
	temp$=tempdir$+"_uninstSelf-Destruct.bat"
	
	bat=WriteFile(temp$)
	
	WriteLine bat,":Repeat"
	WriteLine bat,"del "+Chr$(34)+file$+Chr$(34)
	WriteLine bat,"if exist "+Chr$(34)+file$+Chr$(34)+" goto Repeat"
	WriteLine bat,"rmdir "+Chr$(34)+Left$(dir$,Len(dir$)-1)+Chr$(34)
	WriteLine bat,"del "+Chr$(34)+temp$+Chr$(34)
	
	CloseFile bat
	ShellExecute 0,"open",Chr$(34)+temp$+Chr$(34),"","",0
End Function