Reputation: 1624
I am using NSIS for My Installer. When I uninstall, at the end I want to remove the installation directory and all it's content. I am using the following code
Delete "$INSTDIR\*.*"
RMDir /r "$INSTDIR"
And I notice that the installer deletes all the files in the directory, and then crashes. (i've added log in between the lines and it is not called, The directory stays)
What could be the reason for it to crash like this? I've shutted down the service, and the process, and don't think that anything is in use.
Thank you
EDIT:
Maybe it's because I am deleting the Uninstaller.exe? I tried calling ExecWait
to a batch file that deletes the folder and it also stops working after the delete
Upvotes: 2
Views: 3813
Reputation: 41
Here is a little snippet of my uninstaller section.
I would assume you must remove every single thing you create, so this isn't a wildcard solution.
Section Uninstall
Delete "$SMPROGRAMS\your app\Uninstall.lnk"
Delete "$DESKTOP\your app.lnk"
Delete "$SMPROGRAMS\your app\your app.lnk"
RMDir "$SMPROGRAMS\your app"
RMDir "$INSTDIR\folder"
RMDir "$INSTDIR"
SetAutoClose true
Section End
Upvotes: 3
Reputation: 241
Please refer to the official docs: https://nsis.sourceforge.io/Reference/RMDir
You have to specify /r
flag to remove not empty directories and /REBOOTOK
to remove any directories that can't be removed at run time and will be removed during OS reboot.
Additionally you can't delete current working directory that is set by SetOutPath
command. You need to change it first. See my unistall section below:
Section "Uninstall"
Delete "$DESKTOP\${PRODUCT_NAME}.lnk"
Delete "$SMPROGRAMS\${COMPANY_NAME}\${PRODUCT_NAME}.lnk"
Delete "$INSTDIR\${PRODUCT_NAME}.lnk"
RMDir "$SMPROGRAMS\${COMPANY_NAME}"
Delete "$INSTDIR\*.*"
Delete "$INSTDIR\Uninstall.exe"
SetOutPath "$PROGRAMFILES"
RMDir /r /REBOOTOK "$INSTDIR"
DeleteRegKey /ifempty HKCU "Software\your app name here"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\your app name here"
SectionEnd
Upvotes: 6
Reputation: 250
I use this script to Uninstall all the files and delete the folder using NSIS.
Section "Uninstall"
Delete "$INSTDIR\*.*"
Delete "$INSTDIR\Uninstall.exe"
DeleteRegKey /ifempty HKCU "Software\APPName"
RMDir /r "$INSTDIR"
SectionEnd
Hope this helps.
Upvotes: 2