2007. január 13., szombat

Delete our own application


Problem/Question/Abstract:

How to delete our own application

Answer:

Solve 1:

This solution comes from my idea of doing a installer program. InstallShield(C) and others just uses that solution.

Do not use a Batch file, instead use a small (about 25K) console application that just takes one parameter (the file
that must be deleted) and waits until your application unloads and/or EXE file is unlocked. Just run it from your application before exiting.

program DelFile;
{$APPTYPE CONSOLE}
uses SysUtils, Windows;
begin
  if (ParamCount = 0) then
    Exit;
  repeat
    Sleep(10);
  until (DeleteFile(PChar(ParamStr(1))));
end.

To do a better work, the DelFile.Exe file should be put during the installation of the program into the Windows\Temp folder and runned from there, specifing the complete path of the file that must be deleted.

PRO:
  The batch file can be modified and can be done to not delete your file.
VS:
  You must hide a program in the Windows\Temp folder of a  user, that's not good.


Solve 2:

You can use the registry key:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Runonce

to add a command that will be runned only once, and your application will be deleted next type your Windows will be restarted.

Key name: "DeleteMyOwnApplicationFile"
Key value: "c:\windows\temp\delfile.exe c:\myapp\myapp.exe"

PRO:
  The next time Windows starts, you application will be surelly not
  loaded, also if it's in the Statup folder.
VS:
  You must hide a program in the Windows\Temp folder of a
  user, that's not good.
  The system must be rebooted.  

Solve 3:

Always using, the key registry, don't use your delfile.exe, but:

Key name: "DeleteMyOwnApplicationFile"
Key value: "del c:\myapp\myapp.exe"

...using the DOS "Del" command.

PRO:
  You don't need to hide programs.
VS:
  The system must be restarted.

Nincsenek megjegyzések:

Megjegyzés küldése