@echo off

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

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

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

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

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

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

:: restore registry
REGEDIT /S "%~dp0settings.reg"

MOVE "%AppData%\UltraVNC" "%AppData%\UltraVNC_backup"
MKDIR "%AppData%\UltraVNC"
XCOPY "%~dp0options.vnc" "%AppData%\UltraVNC\" /S /E