0

I write some installer/uninstaller software. In my Uninst programm I need to delete all files in directory, and self file. How to implement this in windows? Running file is blocked

Dcow
  • 1,413
  • 1
  • 19
  • 42

3 Answers3

2

This is not really a Qt question, but more directly Windows. Unlike Linux and OSX, as you've discovered, the file that you're running is locked, so you can't delete it whilst running.

What you can do though is use the RunOnce registry key to separately run a program just once, when a user logs in, which will perform the final delete of the files for you. As stated in the documentation, the RunOnce entry is deleted before it is run, so it performs as expected.

TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85
0

There is no way to delete a file that is currently held open (and an executable file is held open by the OS itself) in Windows. The way most applications solve this is to use the installer framework, and then have a "on boot" handler that cleans up the last remainders.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
0

One trick is to use a batch file for the final cleanup; batch files are allowed to delete themselves. That's because the actual executable in that case is CMD.EXE, which does not need to be deleted.

MSalters
  • 173,980
  • 10
  • 155
  • 350