+
+Function .onInit
+
+ ReadRegStr \$R0 HKLM \
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}-${WARCH}" \
+ "UninstallString"
+ StrCmp \$R0 "" done
+
+ MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
+ "${PROGRAM_NAME} is already installed. Click 'OK' to remove the previous version or 'Cancel' to cancel this upgrade." \
+ IDOK uninst
+ Abort
+
+ uninst:
+ ClearErrors
+ ExecWait '\$R0 _?=\$INSTDIR'
+ IfErrors uninstall_error
+
+ ReadRegStr \$R1 HKLM \
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}-${WARCH}" \
+ "UninstallString"
+ StrCmp \$R1 "" 0 done
+
+ Delete "\$INSTDIR\\uninstall.exe"
+ RMDir "\$INSTDIR"
+ goto done
+
+ uninstall_error:
+
+ MessageBox MB_OK|MB_ICONEXCLAMATION \
+ "Uninstaller did not complete successfully. Continue at your own risk..." \
+ IDOK done
+
+ done:
+
+FunctionEnd
+
+