@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 3
sc delete  ELinkService
rem InstallUtil.exe /u ELinkService
%~d0
cd %~dp0
echo %~dp0
rd /s/q "C:\Program Files\ELink"
rd /s/q C:\Users\Public\Documents\.elink
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    Install ELinkService Success
echo.
echo.
echo *************************************

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



:end
