Listing 1: selfdel.cpp Deleting a running executable file
#include <windows.h> int main() { HMODULE module = GetModuleHandle(0); CHAR buf[MAX_PATH]; GetModuleFileName(module, buf, sizeof buf); CloseHandle(HANDLE(4)); __asm { lea eax, buf push 0 // argument to ExitProcess push 0 // return address of ExitProcess push eax // argument to DeleteFile push ExitProcess // return address of DeleteFile push module // argument to UnmapViewOfFile push DeleteFile // return address of UnmapViewOfFile push UnmapViewOfFile ret } return 0; } // End of File