From 2171748158b11acdd6d9b965dbd96538a6ee6156 Mon Sep 17 00:00:00 2001 From: Marco Esters Date: Thu, 15 Jun 2023 12:29:29 -0700 Subject: [PATCH 1/4] Find registry keys for uninstaller based on INSTDIR --- constructor/nsis/main.nsi.tmpl | 52 ++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/constructor/nsis/main.nsi.tmpl b/constructor/nsis/main.nsi.tmpl index 6f5c8aeb0..a414b7ecb 100644 --- a/constructor/nsis/main.nsi.tmpl +++ b/constructor/nsis/main.nsi.tmpl @@ -66,6 +66,8 @@ Unicode "true" \Uninstall\${UNINSTALL_NAME}" var /global INSTDIR_JUSTME +var /global INSTALLER_VERSION +var /global INSTALLER_NAME_FULL # UAC shield overlay !ifndef BCM_SETSHIELD @@ -1185,10 +1187,36 @@ Section "Uninstall" # carefully. More info at https://docs.conda.io/projects/conda/en/latest/user-guide/troubleshooting.html#solution System::Call 'kernel32::SetEnvironmentVariable(t,t)i("CONDA_DLL_SEARCH_MODIFICATION_ENABLE", "1").r0' + # Read variables the uninstaller needs from the registry + StrCpy $R0 "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" + StrLen $R1 "Uninstall-${NAME}.exe" + IntOp $R1 $R1 + 3 + StrCpy $0 0 + loop_path: + EnumRegKey $1 SHCTX $R0 $0 + StrCmp $1 "" endloop_path + StrCpy $2 "$R0\$1" + ReadRegStr $4 SHCTX $2 "UninstallString" + StrLen $5 $4 + IntOp $5 $5 - $R1 + StrCpy $4 $4 $5 1 + ${If} $4 == $INSTDIR + StrCpy $INSTALLER_NAME_FULL $1 + ReadRegStr $INSTALLER_VERSION SHCTX $2 "DisplayVersion" + goto endloop_path + ${EndIf} + IntOp $0 $0 + 1 + goto loop_path + endloop_path: + # Extra info for pre_uninstall scripts System::Call 'kernel32::SetEnvironmentVariable(t,t)i("PREFIX", "$INSTDIR").r0' System::Call 'kernel32::SetEnvironmentVariable(t,t)i("INSTALLER_NAME", "${NAME}").r0' - System::Call 'kernel32::SetEnvironmentVariable(t,t)i("INSTALLER_VER", "${VERSION}").r0' + StrCpy $0 ${VERSION} + ${If} $INSTALLER_VERSION != "" + StrCpy $0 $INSTALLER_VERSION + ${EndIf} + System::Call 'kernel32::SetEnvironmentVariable(t,t)i("INSTALLER_VER", "$0").r0' System::Call 'kernel32::SetEnvironmentVariable(t,t)i("INSTALLER_PLAT", "${PLATFORM}").r0' System::Call 'kernel32::SetEnvironmentVariable(t,t)i("INSTALLER_TYPE", "EXE").r0' @@ -1202,12 +1230,26 @@ Section "Uninstall" # In case the last command fails, run the slow method to remove leftover RMDir /r /REBOOTOK "$INSTDIR" - DeleteRegKey SHCTX "${UNINSTREG}" + ${If} $INSTALLER_NAME_FULL != "" + DeleteRegKey SHCTX "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$INSTALLER_NAME_FULL" + ${EndIf} + # If Anaconda was registered as the official Python for this version, # remove it from the registry - ReadRegStr $0 SHCTX "Software\Python\PythonCore\${PY_VER}\InstallPath" "" - ${If} $0 == "$INSTDIR" - DeleteRegKey SHCTX "Software\Python\PythonCore\${PY_VER}" + StrCpy $R0 "SOFTWARE\Python\PythonCore" + StrCpy $0 0 + loop_py: + EnumRegKey $1 SHCTX $R0 $0 + StrCmp $1 "" endloop_py + ReadRegStr $2 SHCTX "$R0\$1\InstallPath" "" + ${If} $2 == $INSTDIR + StrCpy $R1 $1 + DeleteRegKey SHCTX "$R0\$1" + goto endloop_py + ${EndIf} + IntOp $0 $0 + 1 + goto loop_py + endloop_py: ${EndIf} SectionEnd From a80b36437a5a28921a05fbddbd63280bd02f1f24 Mon Sep 17 00:00:00 2001 From: Marco Esters Date: Thu, 15 Jun 2023 13:39:15 -0700 Subject: [PATCH 2/4] Add news --- news/684-uninstaller-check-registry | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 news/684-uninstaller-check-registry diff --git a/news/684-uninstaller-check-registry b/news/684-uninstaller-check-registry new file mode 100644 index 000000000..89a04f4f2 --- /dev/null +++ b/news/684-uninstaller-check-registry @@ -0,0 +1,19 @@ +### Enhancements + +* Uninstaller checks the registry for INSTDIR before deleting registry keys (#684) + +### Bug fixes + +* + +### Deprecations + +* + +### Docs + +* + +### Other + +* From fa2040b199eafe4fb8488df30eeac43f26a951da Mon Sep 17 00:00:00 2001 From: Marco Esters Date: Thu, 15 Jun 2023 13:56:57 -0700 Subject: [PATCH 3/4] Remove stray EndIf --- constructor/nsis/main.nsi.tmpl | 1 - 1 file changed, 1 deletion(-) diff --git a/constructor/nsis/main.nsi.tmpl b/constructor/nsis/main.nsi.tmpl index a414b7ecb..374b15955 100644 --- a/constructor/nsis/main.nsi.tmpl +++ b/constructor/nsis/main.nsi.tmpl @@ -1250,7 +1250,6 @@ Section "Uninstall" IntOp $0 $0 + 1 goto loop_py endloop_py: - ${EndIf} SectionEnd !if '@SIGNTOOL_COMMAND@' != '' From e6b0ce906b8aede6b494fb2e440f7971c66eb95f Mon Sep 17 00:00:00 2001 From: Marco Esters Date: Fri, 16 Jun 2023 12:45:45 -0700 Subject: [PATCH 4/4] Update news/684-uninstaller-check-registry Co-authored-by: jaimergp --- news/684-uninstaller-check-registry | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/684-uninstaller-check-registry b/news/684-uninstaller-check-registry index 89a04f4f2..9b13d7c99 100644 --- a/news/684-uninstaller-check-registry +++ b/news/684-uninstaller-check-registry @@ -1,6 +1,6 @@ ### Enhancements -* Uninstaller checks the registry for INSTDIR before deleting registry keys (#684) +* The Windows uninstaller will check the registry for `$INSTDIR` before deleting hardcoded registry keys (#684) ### Bug fixes