0

I am creating an uninstaller which will delete some files and itself. It also needs to delete the folder in which it is placed. I am developing the uninstaller in C++ for Windows only.

I have found methods to delete folders and files but I am not able to find method which deletes the application itself and also deletes the folder that contains it.

Can anyone please guide me how can I achieve this??

Thanks

Lipika
  • 365
  • 2
  • 5
  • 14
  • plenty of results: https://www.google.com/#q=how+to+write+an+uninstaller+C%2B%2B , some even on stack overflow. – Sebastian Mach Apr 17 '13 at 10:18
  • 1
    You should really prefer using existing products like [WiX](http://wix.sourceforge.net/) for this. – Carsten Apr 17 '13 at 10:19
  • @phresnel: FWIW (not much), that URL doesn't work with Javascript disabled. `/search?q=` is the Luddite equivalent. I think what happens here is that Google only directs you to the `#` url when you do a search if it detects you have Javascript. So the site works for everyone, but deep links can't be passed from JS users to non-JS users. – Steve Jessop Apr 17 '13 at 10:44
  • @SteveJessop: Interesting. Just learned two things from that (the other being the term "luddite") :) – Sebastian Mach Apr 17 '13 at 10:53
  • @phresnel: see also https://encrypted.google.com/search?q=hash%20bang%20urls%20evil (if you like reading rants). There's no bang in this URL, but it's the same technique. It's just that Google search results aren't intended to be scraped by crawlers, so don't need the bang. – Steve Jessop Apr 17 '13 at 11:00

2 Answers2

2

You have two options:

1) run a separate process/batch that deletes your files/folder after your app has stopped running. The app can run the process right before it exits.

2) use the Win32 API MoveFileEx() function to mark the files/folders for deletion on the next PC reboot.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
1

You can't do that... When you are trying to delete the .exe of your process, you get access denied, because you are running this particular .exe. You would need to stop your process first, then delete your .exe, but if the process doesn't run it can't do what you want it to do -> deleting all your files. You would need to create an extra process, maybe a batch-job to delete your files.

bash.d
  • 13,029
  • 3
  • 29
  • 42