Mega Code Archive

 
Categories / Delphi / Examples
 

How to have an exe file delete itself

Both Windows 95 and NT provide mechanisms for doing just this. Under Win95 you use the WinInit.ini file. Create a [rename] section and put in entries like "NewName.txt=OldName.txt" to have files renamed, or "nil=OldName.txt" to have them deleted. Windows will perform this at the next boot. Under Windows NT, the MoveFileEx function has a parameter that allows you to defer the move (or delete) until the next boot. It stores the list of files to be processed in the registry.