A smartly deleted program own method Keyword a smartly delete program own method everyone knows that when the general program is running, the executable itself is protected by the operating system, cannot be accessed by rewriting, more Don't mention that you have deleted yourself when you run. Seeing a Undocument method on the homepage of LU0, deleting yourself by changing the file access mode of the system underlying. I saw it very admired.
But is there a function that can be found on the MSDN? Yeffrey richter gives us a sample: deleteme.cpp, name: deleteme.cppwritten by: Jeffrey RichterDescription: allows an executable file to delete itself ******************** ****************************************** / #include #include #include / int WinStance B, LPSTR PSZ, INT N) {// is this the Original EXE or THE CLONE EXE? // if the command-line 1 argument, this is the Original EXE ///iff the command-line> 1 argument, this is the clone exe if (__argc == 1) {// Original EXE: Spawn clone EXE to delete this EXE // Copy this EXEcutable image into the user's temp directory TCHAR szPathOrig [_MAX_PATH], szPathClone [_MAX_PATH]; GetModuleFileName (NULL, szPathOrig, _MAX_PATH) GetTemppath (_MAX_PATH, SZPATHCLON); GetTempFileName (Szpathclone, __text ("del"), 0, szpathclone); CopyFile (szpathorig, szpathclone, false); // *** Note ***: // Open theclone EXE Using file_flag_delete_on_closehandle hfile = cretefile (szpathclone, 0, file_share_read, null, open_existing, file_flag_delete_on_close, Nu LL); // Spawn the clone EXE passing it our EXE's process handle // and the full path name to the Original EXE file.TCHAR szCmdLine [512]; HANDLE hProcessOrig = OpenProcess (SYNCHRONIZE, TRUE, GetCurrentProcessId ()); wsprintf ( Szcmdline, __text ("% s% d /"% s / "), szpathclone, hprocessorig, szpathorig; startupinfo si; zeromemory (& Si, SIZEOF (SI)); Si.cb = sizeof (si); process_information pi; CreateProcess (NULL, SZCMDLINE, NULL, NULL, TRUE, 0, NULL, NULL, & SI, & PI); CloseHandle (HProcessorig); CloseHandle (HFILE); // this Original Process Can Now Terminate.} Else {// Clone EXE: When Original Exe Terminates, delete itHandle HProcessorig =