Skip to content
⌘ NSIS Forum Archive

Errors on uninstall section

11 posts

luca89ct#

Errors on uninstall section

Hi to everyone!

In my $INSTDIR I have a file "file.txt" with 2 lines (12/14). I have a cycle on my script that for each line in file, create a new folder with this code:
Section -MainProgram
${INSTALL_TYPE}
SetOverwrite ifnewer
SetOutPath "$INSTDIR"
File "C:\Users\Gare\Source\Workspaces\etagent-i4u\bin\Debug\ETAgentI4U_setup.exe"
File "C:\Users\Gare\Source\Workspaces\etagent-i4u\bin\Debug\ETAgentI4U_setup.exe.config"
ExecWait '"$INSTDIR\ETAgentI4U_setup.exe"'

FileOpen $0 $INSTDIR\file.txt r
LOOP:
ClearErrors
FileRead $0 $1
${If} $1 <> ""
SetOutPath "$INSTDIR\$1"
File "C:\Users\Gare\Source\Workspaces\etagent-i4u\bin\Debug\App.config"
File "C:\Users\Gare\Source\Workspaces\etagent-i4u\bin\Debug\config.ini"
File "C:\Users\Gare\Source\Workspaces\etagent-i4u\bin\Debug\data.dat"
File "C:\Users\Gare\Source\Workspaces\etagent-i4u\bin\Debug\ETAgentI4U.exe"
File "C:\Users\Gare\Source\Workspaces\etagent-i4u\bin\Debug\ETAgentI4U.exe.config"
File "C:\Users\Gare\Source\Workspaces\etagent-i4u\bin\Debug\Install.bat"
File "C:\Users\Gare\Source\Workspaces\etagent-i4u\bin\Debug\NLog.config"
File "C:\Users\Gare\Source\Workspaces\etagent-i4u\bin\Debug\NLog.dll"
File "C:\Users\Gare\Source\Workspaces\etagent-i4u\bin\Debug\NLog.xml"
File "C:\Users\Gare\Source\Workspaces\etagent-i4u\bin\Debug\RestSharp.dll"
File "C:\Users\Gare\Source\Workspaces\etagent-i4u\bin\Debug\RestSharp.xml"
SetOutPath "$INSTDIR\$1\logs"
${EndIf}
IfErrors +1 LOOP
FileClose $0

SectionEnd
During Install no problem. But when I have to uninstall it, it remove "$INSTDIR\12\logs" and "$INSTDIR\14\logs" folders but not other files. Could you please help me to find the problem? Here my uninstall script:
Section Uninstall
${INSTALL_TYPE}

FileOpen $0 $INSTDIR\file.txt r
LOOP:
ClearErrors
FileRead $0 $1
${If} $1 <> ""


Delete "$INSTDIR\$1\App.config"
Delete "$INSTDIR\$1\config.ini"
Delete "$INSTDIR\$1\data.dat"
Delete "$INSTDIR\$1\ETAgentI4U.exe"
Delete "$INSTDIR\$1\ETAgentI4U.exe.config"
Delete "$INSTDIR\$1\Install.bat"
Delete "$INSTDIR\$1\NLog.config"
Delete "$INSTDIR\$1\NLog.dll"
Delete "$INSTDIR\$1\NLog.xml"
Delete "$INSTDIR\$1\RestSharp.dll"
Delete "$INSTDIR\$1\RestSharp.xml"

!ifdef WEB_SITE
Delete "$INSTDIR\${APP_NAME} website.url"
!endif

RmDir "$INSTDIR\$1\logs"
RmDir "$INSTDIR\$1"
${EndIf}
IfErrors +1 LOOP
FileClose $0

;Delete "$INSTDIR\file.txt"
Delete "$INSTDIR\uninstall.exe"
Delete "$INSTDIR\ETAgentI4U_setup.exe"
Delete "$INSTDIR\ETAgentI4U_setup.exe.config"

RmDir "$INSTDIR"

!ifdef REG_START_MENU
!insertmacro MUI_STARTMENU_GETFOLDER "Application" $SM_Folder
Delete "$SMPROGRAMS\$SM_Folder\${APP_NAME}.lnk"
Delete "$SMPROGRAMS\$SM_Folder\Uninstall ${APP_NAME}.lnk"
!ifdef WEB_SITE
Delete "$SMPROGRAMS\$SM_Folder\${APP_NAME} Website.lnk"
!endif
RmDir "$SMPROGRAMS\$SM_Folder"
!endif

!ifndef REG_START_MENU
Delete "$SMPROGRAMS\I4U Agent per eTesseramenti\${APP_NAME}.lnk"
Delete "$SMPROGRAMS\I4U Agent per eTesseramenti\Uninstall ${APP_NAME}.lnk"
!ifdef WEB_SITE
Delete "$SMPROGRAMS\I4U Agent per eTesseramenti\${APP_NAME} Website.lnk"
!endif
RmDir "$SMPROGRAMS\I4U Agent per eTesseramenti"
!endif

DeleteRegKey ${REG_ROOT} "${REG_APP_PATH}"
DeleteRegKey ${REG_ROOT} "${UNINSTALL_PATH}"
SectionEnd
Anders#
Originally Posted by luca89ct View Post
$1 is the variable with the string that I read each time from file
Yes of course I know that but does it have the value you expect each time through the loop?
luca89ct#
Yes it has the correct value, so during install I have no problems. But only during uninstall.
luca89ct#
Yes, because this line is ok:

it removes the directory, but not the other files
RmDir "$INSTDIR\$1\logs"
luca89ct#
Yes I know but in this code:


Section Uninstall
${INSTALL_TYPE}

FileOpen $0 $INSTDIR\file.txt r
LOOP:
ClearErrors
FileRead $0 $1
${If} $1 <> ""

Delete "$INSTDIR\$1\App.config"
Delete "$INSTDIR\$1\config.ini"
Delete "$INSTDIR\$1\data.dat"
Delete "$INSTDIR\$1\ETAgentI4U.exe"
Delete "$INSTDIR\$1\ETAgentI4U.exe.config"
Delete "$INSTDIR\$1\Install.bat"
Delete "$INSTDIR\$1\NLog.config"
Delete "$INSTDIR\$1\NLog.dll"
Delete "$INSTDIR\$1\NLog.xml"
Delete "$INSTDIR\$1\RestSharp.dll"
Delete "$INSTDIR\$1\RestSharp.xml"

!ifdef WEB_SITE
Delete "$INSTDIR\${APP_NAME} website.url"
!endif

RmDir "$INSTDIR\$1\logs"
RmDir "$INSTDIR\$1"

${EndIf}
IfErrors +1 LOOP
FileClose $0

Delete "$INSTDIR\uninstall.exe"
Delete "$INSTDIR\ETAgentI4U_setup.exe"
Delete "$INSTDIR\ETAgentI4U_setup.exe.config"

RmDir "$INSTDIR"
SectionEnd
It only remove directory "logs" but doesn't execute commands "Delete" before. Do you know why?
luca89ct#
Originally Posted by Anders View Post
RmDir only removes empty directories by default.
Yes I know but in this code

Section Uninstall
${INSTALL_TYPE}

FileOpen $0 $INSTDIR\cod.txt r
LOOP:
ClearErrors
FileRead $0 $1
${If} $1 <> ""

Delete "$INSTDIR\$1\App.config"
Delete "$INSTDIR\$1\config.ini"
Delete "$INSTDIR\$1\data.dat"
Delete "$INSTDIR\$1\ETAgentI4U.exe"
Delete "$INSTDIR\$1\ETAgentI4U.exe.config"
Delete "$INSTDIR\$1\Install.bat"
Delete "$INSTDIR\$1\NLog.config"
Delete "$INSTDIR\$1\NLog.dll"
Delete "$INSTDIR\$1\NLog.xml"
Delete "$INSTDIR\$1\RestSharp.dll"
Delete "$INSTDIR\$1\RestSharp.xml"

!ifdef WEB_SITE
Delete "$INSTDIR\${APP_NAME} website.url"
!endif

RmDir "$INSTDIR\$1\logs"
RmDir "$INSTDIR\$1"
${EndIf}
IfErrors +1 LOOP
FileClose $0

Delete "$INSTDIR\uninstall.exe"
Delete "$INSTDIR\ETAgentI4U_setup.exe"
Delete "$INSTDIR\ETAgentI4U_setup.exe.config"

RmDir "$INSTDIR"

SectionEnd
It only execute "RmDir" commands and not "Delete" commands. Do you know why?
Anders#
That is not possible, either the path is wrong or the files are in use. Try Process Monitor...