@echo off
SETLOCAL
set DAEMON=PdsClientsDaemon.exe
set CURDIR=%cd%
set PKGDIR=%~dp0..
set subScript=stop.bat

call :KillProcess %DAEMON%
call :ExecSubScript "%subScript%"
ENDLOCAL
goto :eof

:KillProcess
set name=%1
tasklist|find /i "%name%"
if %errorlevel%==0 (
	echo "%name% is exist....."
	taskkill /f /t /im %name%

	tasklist|find /i "%name%"
    if %errorlevel%==0 (
        echo "Failed to kill %name%"
    ) else (
        echo "Suc to kill %name%"
    )
) else (
    echo "%name% not exist"
)
goto :eof

:ExecSubScript
set script=%1
cd /d "%PKGDIR%/script"
for /D %%i in (*) do (
    cd /d %%i
    if exist %script% (
		echo "%%i %script%"
		call %script%
	)
    cd /d "%PKGDIR%/script"
)
cd /d "%CURDIR%"
goto :eof