@echo off

cd /d %~dp0
set curpath=%cd%

>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )

set p1=%curpath%\monitor.exe
echo "%p1%"
if exist "%p1%" (
	netsh advfirewall firewall delete rule name="monitor" >NUL
	echo monitor delete to the firewall.
)

set p=%curpath%\RaySyncServer.exe
echo "%p%"
if exist "%p%" (
	netsh advfirewall firewall delete rule name="RaySyncServer" >NUL
	echo RaySyncServer delete to the firewall.
)

set p5=%curpath%\RayFileServer.exe
echo "%p5%"
if exist "%p5%" (
	netsh advfirewall firewall delete rule name="RayFileServer" >NUL
	echo RayFileServer delete to the firewall.
)

set q=%curpath%\proxy\RaySync-Proxy-Server.exe
if exist "%q%" (
	netsh advfirewall firewall delete rule name="RaySync-Proxy-Server" >NUL
	echo RaySync-Proxy-Server delete to the firewall.
)

set p1=monitor.exe
for /f %%i in ('tasklist') do (
	if %%i==%p1% (
		echo monitor is stopping. & taskkill /F /IM monitor.exe >nul 1>nul 2>nul
		call:stopedMonitor
	)
)
echo monitor is not running, don't need to stop.

:stopedMonitor
set q=RaySync-Proxy-Server.exe
for /f %%i in ('tasklist') do (
	if %%i==%q% echo RaySync-Proxy-Server is stopping. & taskkill /F /IM RaySync-Proxy-Server.exe >nul 1>nul 2>nul
)

set p=RaySyncServer.exe
for /f %%i in ('tasklist') do (
	if %%i==%p% echo RaySyncServer is stopping. & taskkill /F /IM RaySyncServer.exe >nul 1>nul 2>nul
)
set p5=RayFileServer.exe
for /f %%i in ('tasklist') do (
	if %%i==%p5% echo RayFileServer is stopping. & taskkill /F /IM RayFileServer.exe >nul 1>nul 2>nul
)

REM set startMenuFolder_pan=%SystemDrive%
REM set startMenuFolder=%SystemDrive%\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
REM if exist  "%startMenuFolder%\Raysync.bat" (
	REM del /f/s/q "%startMenuFolder%\Raysync.bat" >nul 1>nul 2>nul
REM )

call status.bat

rem echo "### call stop.bat @ %date% %time% ###" >> log/stop.log

rem echo RaySyncServer is not running, don't need to stop.




pause
