***************************************************************** * Neveprise Inc. Delphi FAQ * ***************************************************************** * Section: Files Topic: Delete running exe * * Created: July 27th, 1999 Revised: July 27th, 1999 * * Updates: www.neveprise.de Info: support@neveprise.de * ***************************************************************** Q: How can I delete a running executeable? A: Practically, it is not possible to delete a running binary. But there are two other ways you might use: a) you have to launch another app that deletes the calling one or b) you can tell Windows to remove your app (e.g. a deinstallation app). That can be done via Registry: there is a key that is queried once, executed what is in it and deleted after that by Windows. The Key RunOnce or RunOnceEx: procedure DelRunningExeH(FileOrDirName: string; IsDirectory: boolean); var Reg: TRegIniFile; begin Reg:=TRegIniFile.Create(''); if IsDirectory=false then begin Reg.WriteString('\Software\Microsoft\Windows\CurrentVersion \RunOnce','FileOrDirName','command.com /c del '+FileOrDirName); end else begin Reg.WriteString('\Software\Microsoft\Windows\CurrentVersion \RunOnce','FileOrDirName','command.com /c rd '+FileOrDirName); end; Reg.Free; end; As you see, we just write a command line like in DOS into that key's value. The key itself can be named whatever you like. What Windows does on boot is this: it enums all idents in that key RunOnce and passes the contents / the value to the command line interpreter (it must not be DOS!); then this ident and the value will be removed to avoid a second execution, what will cause errors each time Windows restarts. Blazko