Archive: RMDir not deleting root install folder


RMDir not deleting root install folder
I've just recompiled the installer code using NSIS 2.07 instead of 2.05 but for some reason the uninstaller doesn't allow deleting the root install folder.

I don't recall having this error in NSIS 2.05.

I'm using the below code to delete the install folders:

;**************************************************************************************************
;Delete files created upon installation
;**************************************************************************************************

;Delete "$INSTDIR\Icons\*.*"
;Delete "$INSTDIR\Help\*.*"
;Delete "$INSTDIR\*.*"

;**************************************************************************************************
;Delete folders created upon installation
;**************************************************************************************************
RMDir /r "$INSTDIR"


Also in the script I have:

**************************************************************************************************
;Installer default installation folder
;**************************************************************************************************
InstallDir "$PROGRAMFILES\xxx.yyy\zzz www 2006"

What's going wrong? All sub-folders get deleted just not the root install folder.

Thanks.


Windows not deletes application's current folder, so you should remove /SetOutPath $INSTALLDIR/ if this presents and not required in uninstaller (full paths in most cases) or change it before RMDir /SetOutPath ../.


Originally posted by Takhir
Windows not deletes application's current folder, so you should remove /SetOutPath $INSTALLDIR/ if this presents and not required in uninstaller (full paths in most cases) or change it before RMDir /SetOutPath ../.
Hmmm

I haven't changed any code (just names of files/folders) since when I compiled it with NSIS 2.05 so why suddenly does one need to take a different approach?

I don't have SetOutPath $INSTALLDIR in my uninstaller section.

I'm thinking it must be something to do with InstallDir being a two level folder (i.e. xxx\yyy). In such case it's deleting the sub folder (yyy) but not the root folder (xxx).

Any other ideas anyone?


NSIS Documentation:
Note that the current working directory can not be deleted. The current working directory is set by SetOutPath.
Why you use (RMDir /r "$INSTDIR")? Try this:
SetOutPath "$TEMP"
Delete "$INSTDIR\Icons\*.*"
Delete "$INSTDIR\Help\*.*"
Delete "$INSTDIR\*.*"
RMDir "$INSTDIR"
or
SetOutPath "$TEMP"
RMDir /r "$INSTDIR"

I changed it to what's below in the uninstaller sectio but the root installation folder still exists after I've run the uinstaller.

It's content gets deleted, just not the root folder hence it's always left empty.

SetOutPath "$TEMP"
RMDir /r "$INSTDIR"

This is confusing, I could swear it worked fine with NSIS 2.05 :(


Try Sleep 1000 before it.

-Stu


Originally posted by Afrow UK
Try Sleep 1000 before it.

-Stu
Put in the sleep and no change.

I'm beginning to scratch out the remaining hair I have :)

I don't get it because neither is it a protected folder or a hidden or a system one.

Below is my uninstall code, all works except the root folder delete:

*******************

;--------------------------------
;UNINSTALLER SECTIONS #############################################################################


;/////////////////////////////////////////////////////////
Section "Uninstall"
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

;**************************************************************************************************
;Delete files created upon installation
;**************************************************************************************************

;Delete "$INSTDIR\Icons\*.*"
;Delete "$INSTDIR\Help\*.*"
;Delete "$INSTDIR\*.*"

;**************************************************************************************************
;Delete folders created upon installation
;**************************************************************************************************

Sleep 1000
SetOutPath "$TEMP"
RMDir /r "$INSTDIR"

;**************************************************************************************************
;Delete Start Menu links
;**************************************************************************************************

!insertmacro MUI_STARTMENU_GETFOLDER Application $R0

Delete "$SMPROGRAMS\$R0\${STARTMENU_LINK_APP_NAME}.lnk"
Delete "$SMPROGRAMS\$R0\${STARTMENU_LINK_APP_UNINSTALL}.lnk"
Delete "$SMPROGRAMS\$R0\${STARTMENU_LINK_APP_HELP}.lnk"

Delete "$QUICKLAUNCH\${STARTMENU_LINK_APP_NAME}.lnk"

;Delete empty start menu parent diretories
StrCpy $R0 "$SMPROGRAMS\$R0"

RMDir $R0

ClearErrors

;**************************************************************************************************
;Delete created registry keys
;**************************************************************************************************
DeleteRegKey HKLM "Software\xxx.yyy"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\xxx.yyy zzz www 2006"
DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "yyy www 2006"

SectionEnd

;/////////////////////////////////////////////////////////
Section "-un.Uninstall VB6 runtimes"
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

!insertmacro UnInstallLib REGDLL SHARED NOREMOVE "$SYSDIR\msvbvm60.dll"
!insertmacro UnInstallLib REGDLL SHARED NOREMOVE "$SYSDIR\oleaut32.dll"
!insertmacro UnInstallLib REGDLL SHARED NOREMOVE "$SYSDIR\olepro32.dll"
!insertmacro UnInstallLib REGDLL SHARED NOREMOVE "$SYSDIR\comcat32.dll"
!insertmacro UnInstallLib DLL SHARED NOREMOVE "$SYSDIR\asycfilt.dll"
!insertmacro UnInstallLib TLB SHARED NOREMOVE "$SYSDIR\stdole2.tlb"

SectionEnd

No hidden files in it?
What about after a reboot with /rebootok?

-Stu


Originally posted by Afrow UK
No hidden files in it?
What about after a reboot with /rebootok?

-Stu
You suggesting I force users to reboot after uninstallation? NSIS 2.05 worked fine.

I'm going to checkt this now but I don't think it can be anything to do with the "." in the folder name.

I've also specified the install DIR as a three stage folder as below, but this is normal right?

InstallDir "$PROGRAMFILES\xxx.yyy\zzz www 2006"


Well it's not the "." in the folder name that's for sure, just checked! :(


I think you'll need a RMDirUp function that recursively removes any empty parent folders.

I'll try to write one up and post it. I have this same issue.


RMDir /r should do that. I just tried it and had no problems (2.07).

Edit: No I'm not saying you must get the user to restart after uninstall. I'm asking you if it works after a reboot.

-Stu


Neither "RMDir /r $INSTDIR" or "RMDir /r /REBOOTOK $INSTDIR" remove the empty parent directories for me, before OR after a reboot.

This is what I came up with and works fine:


Function un.RMDirUP
!define RMDirUP '!insertmacro RMDirUPCall'

!macro RMDirUPCall _PATH
push '${_PATH}'
Call un.RMDirUP
!macroend

; $0 - current folder
ClearErrors

Exch $0
;DetailPrint "ASDF - $0\.."
RMDir "$0\.."

IfErrors Skip
${RMDirUP} "$0\.."
Skip:

Pop $0

FunctionEnd


Use:

RMDir /r "$INSTDIR"
${RMDirUP} "$INSTDIR"

Added the code above but where it calls it the compiler isn't very happy:

Section: "Uninstall"
RMDir: /r "$INSTDIR"
Invalid command: ${RMDirUP}
Error in script "C:\XXX\YYY\Install\Install_NSIS\Setup.nsi" on line 264 -- aborting creation process


All I did was put in the below as mentioned above:

RMDir /r "$INSTDIR"
${RMDirUP} "$INSTDIR"


Before the Uninstall section you need to include that function I posted as well.


Geez I feel really stupid for asking the last question because I remembered the answer the second I read "You need....", I think it's showing I haven't been using NSIS for a while, :)

Anyway compiled and it now deletes the root folder so all in all excellent!

Thanks so much for getting this ironed out, :)