Skip to content
⌘ NSIS Forum Archive

How to make sure files and directories are deleted after uninstall ?

8 posts

klasdfe#

How to make sure files and directories are deleted after uninstall ?

In my uninstaller, i try to delete some files and directories.
Ex:
delete "$INSTDIR\images\*.*"
rmdir "$INSTDIR\images"
But the result is different each time i run the uninstaller, one time every files and directories are deleted, one time some files and directories are exists.
How to make sure files and directories are deleted after uninstall ?
ChocJunkie#
If you're sure you want to delete a directory you can use:
RMDir /r
instead of using Delete+RMDir on the same directory.
This way you'll delete the directory recursively - all files and subfolders will be deleted too.

And are you checking for errors after Delete/RMDir?
Zinthose#
Also:
If you add the /REBOOTOK switch it will remove the directories on the next reboot if the installer is unable to.

RMDir /r /REBOOTOK ${DIRTOKILL} 
klasdfe#
Originally posted by ChocJunkie

And are you checking for errors after Delete/RMDir? [/B]
How to check for errors ? I think may be when i deleted these files they were in use.

If you add the /REBOOTOK switch it will remove the directories on the next reboot if the installer is unable to.
Thank you for your suggestion, i want to know the detail errors when i can't delete a file. In my circumstance, i know that it doesn't necessary to reboot computer.
Zinthose#
Try this...

ClearErrors
RMDir $INSTDIR
IfErrors +1 NoErrors
    DetailPrint "Everytime an error occurs, God kills a kitten."
NoErrors: 
klasdfe#
In order to simple, i try :

ClearErrors
RMDir /r $INSTDIR
IfErrors +1 +2
MessageBox MB_OK "Can't delete"

I got that message box ! I also reinstall and try to uninstall again, that time no error. Why one time i can't delete a file, and other time i can. How to make the result always the same.
klasdfe#
These files were in used when the uninstaller try to delete.
Try:
RMDir /r /rebootok $INSTDIR

And after reboot my computer, these files were deleted. In order to avoid reboot, the application must close before the uninstaller run. How do i know if my application was running, and exit it ?
Wizou#
you can implement a DDE server in your application (quite easy under MFC) and use nsisDDE plugin to detect and exit your running application