- NSIS Discussion
- How to make sure files and directories are deleted after uninstall ?
Archive: How to make sure files and directories are deleted after uninstall ?
klasdfe
21st October 2009 03:46 UTC
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
21st October 2009 10:21 UTC
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
21st October 2009 17:41 UTC
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
22nd October 2009 07:56 UTC
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
22nd October 2009 12:46 UTC
Try this...
ClearErrors
RMDir $INSTDIR
IfErrors+1 NoErrors
DetailPrint "Everytime an error occurs, God kills a kitten."
>NoErrors:
klasdfe
26th October 2009 08:56 UTC
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
10th November 2009 08:15 UTC
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
10th November 2009 08:46 UTC
you can implement a DDE server in your application (quite easy under MFC) and use nsisDDE plugin to detect and exit your running application