@echo off

color 07


echo.
echo.
rem set path=C:\Windows\Microsoft.NET\Framework64\v4.0.30319;%path%

taskkill /F /IM nginx.exe

sc config ELinkService start= disabled
net stop ELinkService
timeout /T 5

sc delete  ELinkService
timeout /T 3

%~d0
cd %~dp0
echo %~dp0

rem InstallUtil.exe /u "C:\Program Files\elink\ELinkService.exe"

rd /s/q "C:\Program Files\ELink"
rem rd /s/q C:\Users\Public\Documents\.elink
rem rd /s/q C:\Users\Public\Documents\.elink\log
MD "C:\Program Files\ELink"
xcopy *.* "C:\Program Files\ELink\" /s /e /c /y /h /r

c:
cd "C:\Program Files\ELink"

InstallUtil.exe ELinkService.exe

if not errorlevel 0 goto fail

netsh advfirewall firewall delete rule name=ELink-http
netsh advfirewall firewall delete rule name=ELink-service
netsh advfirewall firewall delete rule name=ELink-nginx
netsh advfirewall firewall add rule name ="ELink-http" dir=in localport=8090 protocol=tcp action=allow
netsh firewall set allowedprogram "C:\Program Files\ELink\ELinkService.exe" ELink-service ENABLE
netsh firewall set allowedprogram "C:\Program Files\ELink\nginx.exe" ELink-nginx ENABLE

net start ELinkService
color 07
rem cls
echo.
echo.
echo *************************************
echo.
echo    Update ELinkService Success
echo.
echo.
echo *************************************

rem pause
goto end
:fail
rem cls
color 4f
echo.
echo.
echo *************************************
echo.
echo    Update ELinkService failed
echo.
echo *************************************
echo.
rem pause



:end
