• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

How to uninstall a program?

I would need to do this: from my application I want to be able to uninstall the application itself, deleting its executable from HD.
The problem is: it's impossible to delete the executable while it's still running.
I was wondering if there's a way to tell Windows to delete a file and a directory when it's starting up. I mean: I noticed that many installation or uninstallation programs ask the user to reboot the system, I think because they cannot remove programs currently running otherwise (think of uninstalling a program a part of which is running in the system tray...).
My question is: do I have to set any key in the registry or something like this to tell Windows to remove a file and a directory (the executable and the folder it's installed in) upon startup?
Otherwise, is there any way to uninstall my application without having to use an external executable to delete it?
Thanks in advance,
  • 2
  • 2
1 Solution
Have your uninstall program remove everything it needs and then remove the uninstall program upon reboot by using this:

  fRun:='command.com /c del c:\windows\Uninstall.EXE';
  with TRegIniFile.Create('') do

mauromolAuthor Commented:
As I would need to uninstall the program from itself, I may do in this way: let's call program A my program and program B the uninstall program.
I could run B from A, passing to it a handle of A. Then, I could terminate A from B using that handle, so that I can after delete A's executable from B.
But how to do this?
Possibly, but it is best to have the user start the uninstaller. I always put my program on the start programs menu with the uninstaller following. In your case, you still need to get rid of B.
mauromolAuthor Commented:
The fact is the installer/uninstaller I'm using must perform many operations before simply uninstalling the program. I integrate a lot of funtions in it, among which the uninstall features.
However, I thought I may put two calls into RunOnce registry key, one to delete this installer/uninstaller and one to delete its subfolder in c:\Program Files...
Thanks CalvinDay!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now