@echo off

:: save registry
REGEDIT /S /E "%~dp0settings.reg" "HKEY_CURRENT_USER\Software\ORL\VNCviewer"

:: cleanup registry
REG DELETE "HKEY_CURRENT_USER\Software\ORL\VNCviewer" /f
REG COPY "HKEY_CURRENT_USER\Software\ORL\VNCviewer_backup" "HKEY_CURRENT_USER\Software\ORL\VNCviewer" /s /f
REG DELETE "HKEY_CURRENT_USER\Software\ORL\VNCviewer_backup" /f

REG DELETE "HKEY_CLASSES_ROOT\.vnc" /f
REG COPY "HKEY_CLASSES_ROOT\.vnc_backup" "HKEY_CLASSES_ROOT\.vnc" /s /f
REG DELETE "HKEY_CLASSES_ROOT\.vnc_backup" /f

REG DELETE "HKEY_CLASSES_ROOT\VncViewer.Config" /f
REG COPY "HKEY_CLASSES_ROOT\VncViewer.Config_backup" "HKEY_CLASSES_ROOT\VncViewer.Config" /s /f
REG DELETE "HKEY_CLASSES_ROOT\VncViewer.Config_backup" /f

REG DELETE "HKEY_CURRENT_USER\AppEvents\EventLabels\VNCviewerBell" /f
REG COPY "HKEY_CURRENT_USER\AppEvents\EventLabels\VNCviewerBell_backup" "HKEY_CURRENT_USER\AppEvents\EventLabels\VNCviewerBell" /s /f
REG DELETE "HKEY_CURRENT_USER\AppEvents\EventLabels\VNCviewerBell_backup" /f

REG DELETE "HKEY_CURRENT_USER\AppEvents\Schemes\Apps\VNCviewer" /f
REG COPY "HKEY_CURRENT_USER\AppEvents\Schemes\Apps\VNCviewer_backup" "HKEY_CURRENT_USER\AppEvents\Schemes\Apps\VNCviewer" /s /f
REG DELETE "HKEY_CURRENT_USER\AppEvents\Schemes\Apps\VNCviewer_backup" /f

REG DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vncviewer.exe" /f
REG COPY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vncviewer.exe_backup" "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vncviewer.exe" /s /f
REG DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vncviewer.exe_backup" /f

XCOPY "%AppData%\UltraVNC\options.vnc" "%~dp0" /S /E /Y
RMDIR "%AppData%\UltraVNC" /S /Q
MOVE "%AppData%\UltraVNC_backup" "%AppData%\UltraVNC"

RMDIR "%AppData%\UltraVNC" /Q