@echo off
rem Info zur Version:
rem Datum        Wer     Info
rem 28.04.2017   J.Fes   ueberarbeitet
rem 29.06.2023   J.Fes   Optimiced

if "%~2" equ "" (
 Echo Err: [Call %0]& Echo Err: missing paramters
 Echo Inf: P1=Prog_N P2=Prog_DPNE
 Echo Example: PlmJobManagerWatchDog starten
 Echo call "ProgStart_If_NotRuning.cmd" "PLMJobManagerWatchDog" "C:\Programme\PLMJobManagerWatchDog\PLMJobManagerWatchDog.exe"
 goto :eof
 )
setlocal
 rem -- Rootpfade setzen
 set PrgToRun_N=%~1
 set PrgToRun_DPNE=%~2
 set PrgToRun_NE=%~nx2
 tasklist /FI "IMAGENAME eq %PrgToRun_N%*" 2>nul | findstr /i /c:"%PrgToRun_N%">nul
 set PrgToRun_isNotRuning=%errorlevel%
 if "%PrgToRun_isNotRuning%" neq "0" goto :startP
 Echo Prg Start is already running....: YES: %PrgToRun_N%
 goto :myEnd

:startP
 Echo Prg Start is already running....: NO Start now %PrgToRun_N%
 if /I "%PrgToRun_DPNE:~-4%" equ ".cmd" goto :startP_cmd
 if /I "%PrgToRun_DPNE:~-4%" equ ".bat" goto :startP_cmd

 rem Echo start "%PrgToRun_NE%" "%PrgToRun_DPNE%" %3 %4 %5 %6 %7 %8 %9
 start "%PrgToRun_NE%" "%PrgToRun_DPNE%" %3 %4 %5 %6 %7 %8 %9
 goto :myEnd

:startP_cmd
 start "%PrgToRun_NE%" /MIN cmd /C %PrgToRun_DPNE% %3 %4 %5 %6 %7 %8 %9
 goto :myEnd

:myEnd
endlocal
goto :eof

