Sumber Kode

Delete Self - Procedure to close and delete the current application

  • delphibasics
  • Nov 19' 14
  • Delphi
  • 110
  • 276
  • United States
This procedure can be used to close the current instance of the program and delete the file, thereby removing all trace of the file from a computer.
It is useful in installation applications.
program DeleteSelf;

{
    Website: www.delphi.co.nr
    Tested: Windows XP
}
 

uses
  Windows;

procedure xDeleteSelf;
var
  module: HMODULE;
  buf: array[0..MAX_PATH - 1] of char;
  p: ULONG;
  hKrnl32: HMODULE;
  pExitProcess, pDeleteFile, pFreeLibrary: pointer;
begin
  module := GetModuleHandle(nil);
  GetModuleFileName(module, buf, sizeof(buf));
  CloseHandle(THandle(4));
  p := ULONG(module) + 1;
  hKrnl32 := GetModuleHandle('kernel32');
  pExitProcess := GetProcAddress(hKrnl32, 'ExitProcess');
  pDeleteFile := GetProcAddress(hKrnl32, 'DeleteFileA');
  pFreeLibrary := GetProcAddress(hKrnl32, 'FreeLibrary');
  asm
    lea eax, buf
    push 0
    push 0
    push eax
    push pExitProcess
    push p
    push pDeleteFile
    push pFreeLibrary
    ret
  end;
end;

begin
  xDeleteSelf;
end.

Powered by
Pasar Kode Partner

Share

  • Tags :
comments powered by Disqus

Kode Terkait

uFMOD Example - Play .xm files from disk, memory or resource.

Pngimage by Aphex - Create, convert to and edit .png images in delphi.

Crafting a PE File with Delphi - Creating a pe file from scratch.

Change resource strings at runtime.

Alternative Sleep Methods

Create a form with Windows API.

Drag and Drop

Retreive default browser path

Create a functioning form with Windows API.

HHUtils 1.0 - A collection of useful delphi functions.



Kategori