@echo off
if "%2"=="" goto exit
title Reinstalling Portable %3
:targwait
tasklist | findstr /i %3.exe 1>nul
if errorlevel 1 goto targexit
echo waiting for %3 to exit...
ping 127.0.0.1 -n %1 >nul
goto targwait
:targexit
copy /y %2\*.* .
if errorlevel 1 goto errcopy
start "" "%cd%\%3"
if errorlevel 1 goto errstart
rmdir /s /q %2
goto exit
:errcopy
rmdir /s /q %2
echo reinstall %3 FAILED
pause
goto exit
:errstart
rmdir /s /q %2
echo can't restart %3
pause
:exit
