@echo off

SET VNCDIR="c:\program files\DeltaVNC"
SET TMPDIR=%~d0%~p0

SET VNCSDIR=.\vnc\x64
SET ARHIT = "x64"

If "%PROCESSOR_ARCHITECTURE%"=="x86" Set VNCSDIR=.\vnc\x32
If "%PROCESSOR_ARCHITECTURE%"=="x86" Set ARHIT="x32"

CALL :install_vnc_server
pause
exit 0

:install_vnc_server
CD %TMPDIR%

echo Stop uvnc service
sc stop uvnc_service
echo Remove uvnc service
sc delete uvnc_service 
echo Remove old VNC service
%VNCSDIR%\tvnserver.exe -remove -silent
echo AddAndDelete firewall rule for port 5900
netsh advfirewall firewall delete rule name="VNC5900"
netsh advfirewall firewall add rule name="VNC5900" protocol=TCP localport=5900 action=allow dir=IN
echo Create dir %VNCDIR%
MKDIR %VNCDIR%
echo Write data to registr
regedit.exe /s %VNCSDIR%\tighvncserv.reg
echo CopyFiles
ping 127.0.0.1 -n 2 > nul
COPY %VNCSDIR%\tvnserver.exe %VNCDIR%\tvnserver.exe
COPY %VNCSDIR%\tvnviewer.exe %VNCDIR%\tvnviewer.exe
COPY %VNCSDIR%\screenhooks32.dll %VNCDIR%\screenhooks32.dll
If "%ARHIT%"=="x64" COPY %VNCSDIR%\screenhooks64.dll %VNCDIR%\screenhooks64.dll
If "%ARHIT%"=="x64" COPY %VNCSDIR%\hookldr.exe %VNCDIR%\hookldr.exe

CD %VNCDIR%\
echo Install VNC server
ping 127.0.0.1 -n 3 > nul
%VNCDIR%\tvnserver.exe -install -silent
echo Start VNC service
sc start tvnserver
exit /b 0

:exit
