Self Deleting Exe after Running (new version)
Posted: Tue Aug 03, 2004 10:09 am
Broken on newer Windows. Alternatives below.
below is a sourcecode to write an uninstaller which delete itself after running (goto deleteItself ) , no restart or Batchfile needed .
this version used the possibility to run code from stack
below is a sourcecode to write an uninstaller which delete itself after running (goto deleteItself ) , no restart or Batchfile needed .
this version used the possibility to run code from stack

Code: Select all
; Name: Self deleter
; Purpose:Good to use for an Uninstaller
;
; This file (if compiled to exe) delete itself after finishing (executes code on the stack ;) )
; should also work under Win89, but never tested
;
;Enable InlineASM !
;
; coded/adapted/enhanced (Powerbasic-version from Wayne Diamond, thx wayne :) )
; by Siegfried Rings
; have fun !
MessageRequester("info","self-deleter",0)
DeleteItself:
hModule = GetModuleHandle_(0)
szModuleName.s=Space(512)
GetModuleFileName_(hModule, szModuleName, Len(szModuleName))
hKrnl32 = GetModuleHandle_("kernel32.dll")
pExitProcess = GetProcAddress_(hKrnl32, "ExitProcess")
pDeleteFile = GetProcAddress_(hKrnl32, "DeleteFileA")
pFreeLibrary = GetProcAddress_(hKrnl32, "FreeLibrary")
pUnmapViewOfFile = GetProcAddress_(hKrnl32, "UnmapViewOfFile")
;Set Fileattributes if Writeprotectet!
SetFileAttributes_(szModuleName,0)
#Win9x = 0 ;do OS-detection code by yourself !
If #Win9x <> 0
; MessageRequester("Info"," Win95/98/ME ",0)
MOV eax,szModuleName
PUSH 0
PUSH 0
PUSH eax
PUSH pExitProcess
PUSH hModule
PUSH pDeleteFile
PUSH pFreeLibrary
RET
Else
; MessageRequester("Info"," NT4/2K/XP/.NET ",0)
CloseHandle_(4)
MOV eax,szModuleName
PUSH 0
PUSH 0
PUSH eax
PUSH pExitProcess
PUSH hModule
PUSH pDeleteFile
PUSH pUnmapViewOfFile
RET
EndIf