JohnChen analyzed a self-deleting program written by Gary Nebbett. It is a very subtle piece of code. The subtlety is that the process is still there, but the executable file has been deleted.
I also wrote a piece of self-deleting code some time ago, but it was not that advanced. I just used the batch processing function and called my function at the end of the program to delete myself. Now post the function code.
void SelfDelete()
{
static char templ[] =
":Repeatrn"
"del "%s"rn"
"if exist "%s" goto Repeatrn"
"rmdir %s rn"
"del "%s"" ;
static const char tempbatname[] = "_uninsep.bat" ;
char modulename[MAX_PATH] ;
char temppath[MAX_PATH] ;
char folder[MAX_PATH] ;
GetTempPath(MAX_PATH, temppath) ;
strcat(temppath, tempbatname) ;
GetModuleFileName(NULL, modulename, MAX_PATH) ;
strcpy (folder, modulename) ;
char *pb = strrchr(folder, '\');
if (pb != NULL)
*pb = 0;
HANDLE hf
DWORD len ;
char *bat ;
bat = (char*)alloca(strlen(templ) +
strlen(modulename) * 2 + strlen(temppath) + 20) ;
wsprintf(bat, templ, modulename, modulename, folder, temppath) ;
WriteFile(hf, bat, strlen(bat), &len, NULL) ;
CloseHandle(hf) ;
ShellExecute(NULL, "open", temppath, NULL, NULL, SW_HIDE);
}
}