Archive: Second install directory not uninstalled


Second install directory not uninstalled
Hello
I tried a script with two page directories. One for program files and one for data.
All works fine except the uninstall of the data directory.
All files and the the main install dir $INSTDIR are removed but not the
$INSTDIR2 folder.

I assume that $INSTDIR is not recogniced if uninstaller is starting?

Thanks for any help.

Here a part of my NSI code

-----------------------------------------------
# First directory page for program files.
!insertmacro MUI_PAGE_DIRECTORY
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES

##########################################################
##########################################################
# Second directory page for data files.
var INSTDIR2
!define MUI_DIRECTORYPAGE_VARIABLE $INSTDIR2
!define MUI_PAGE_CUSTOMFUNCTION_PRE DirectoryPre
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES

Function DirectoryPre
StrCpy $INSTDIR2 "$PROGRAMFILES\Data"
FunctionEnd

##########################################################
##########################################################

; Finish page
!insertmacro MUI_PAGE_FINISH

; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES

; Language files
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "French"
!insertmacro MUI_LANGUAGE "German"

; MUI end ------

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup.exe"
InstallDir "$PROGRAMFILES\ITest"
ShowInstDetails show
ShowUnInstDetails show
....
....
Section Uninstall
RMDir /r "$INSTDIR2/Data"

Delete "$INSTDIR\${PRODUCT_NAME}.url"
Delete "$INSTDIR\uninst.exe"
Delete "$INSTDIR\index.php"
Delete "$INSTDIR\index.html"

Delete "$SMPROGRAMS\ITest\Uninstall.lnk"
Delete "$SMPROGRAMS\ITest\Website.lnk"

RMDir "$SMPROGRAMS\ITest"
RMDir "$INSTDIR"

DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
SetAutoClose true
SectionEnd
--------------------------------------------------


Variables are not transferred from the installer to the uninstaller. $INSTDIR is also not transferred. Instead, it contains the path where uninstall.exe is stored (in the hopes that this is the same as $INSTDIR was in the installer...). To transfer variables, use the registry or write the values to a file.


Done with ReadRegStr
Hello,
thanks a lot for your help

Originally posted by MSG
Variables are not transferred from the installer to the uninstaller. $INSTDIR is also not transferred. Instead, it contains the path where uninstall.exe is stored (in the hopes that this is the same as $INSTDIR was in the installer...). To transfer variables, use the registry or write the values to a file.
Now I have written the variable $Instdir2 to the registry
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DataDirectory" "$INSTDIR2\Directories"

and in the unistall section I read the path from registry
ReadRegStr $R1 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DataDirectory"
RMDir /r "$R1"
...

It works. If there is any problem with this code or if there is something to improve, please let me know.

best regards
Hawk

While the basic idea is correct, there are two possible problems with that code. First of all, the regkey may not exist for some reason. In that case you'll end up calling RmDir /r "", which probably does nothing, but might perhaps also delete something you don't want deleted at all. So add a check: ${If} $R1 != "" RmDir etc ${EndIf}. Second, using the /r flag in RmDir is extremely dangerous. If some idiot end-user decided to put stuff inside your INSTDIR, you'll be deleting things the user doesn't want deleted. So it's almost always better to delete only those files you KNOW you want to delete:
Delete $R1\filename1.ext
Delete $R1\filename2.ext
RmDir $R1


Hello MSG,
thanks again for this tip.
Normally I always delete the files and directory like you recommend.
But, how can you delete and remove files from directories which have files included that are not recognized from installer?
Like in my Data directory. In this directory after installation there are many files copied, there a session files from the system. There are tmp files from Windows. All these files I do not know before installation.


How deleting / uninstalling unknown files ?
Hello,
I want to ask again:
I know that RMdir /r is not a good way for uninstalling files and directories.
But how can you make an uninstall of a directory which containts temporary files, like session files or log files?
all these files are created after the installation. So you cannot include it into the uninstall section.

Thanks for any hint.

regards
hawk


How deleting / uninstall unknown files?
Hello,
I know that RMDIR /r is not a good way.
But how can you make an uninstall of a directory which contains files after installation?
For example Session files or log files which are created temporarely.
Or if other programs copies files in this directory.
All these files are not known while installing and cannot be added into the uninstall section

Thanks for any idea.
regards
hawl


You can delete files in a folder with wildcards, but you really should only remove the files you installed and files you know your program makes/might make and can safely be deleted. Any other files, such as a user's configuration settings and files written by other applications, either leave them alone or ask the user if they want to delete those, too.


I would never use RMDir /r in uninstall. If you give it an empty string and you have not set the current working directory ($OUTDIR) you will remove everything from C:\. I have heard of this happening after uninstalls and I would not be surprised if it was a lazily written NSIS uninstaller.

If you must be lazy and use RMDir /r, look at validating the contents of $INSTDIR before using it:
http://nsis.sourceforge.net/Validati...fore_uninstall

Stu