@echo off

rem Startscript für: JobManagerV3
rem Funktion: startet die Programme des Jobmanagers
rem #New.: 31.05.2007 J.Fes (c) J.Feuerstein 2007..2016
rem #LUp.: 19.01.2016 J.Fes Update V2 to V3
rem #LUp.: 15.08.2018 S.Gueth added JobMgr_StartAsService variabe (when JobClient or JobServer should be started as a service)
rem                   Example:
rem                   set JobMgr_StartAsService=ON
rem                   call \\addPLM\JobManager\ProgEntw\Ver03\JobManagerV3\02-BinClient\JobManagerStart.cmd /Client /ServerSettingsXML TestSystem /JobClientStartMode Automatic
rem #LUp.: 20.02.2019 renamed ENV StartAsService to JobMgr_StartAsService=ON
rem #LUp.: 05.03.2019 S.Gueth check var StartAsService for compatiblity
rem #LUp.: 25.04.2019 J.Fes repair ApplicationInfo

rem ----------------------------------------------------------------------------
 set MyApplBase_TP=JobManagerV3

 rem #LUp: 27.02.2019 J.Fes
 REM #Doc: get ApplicationInfo
 REM #LUp: 25.06.2019/J.Fes repair ApplicationInfo
 if exist "%~dp0ApplicationInfo.cmd" call "%~dp0ApplicationInfo.cmd" GetVerInfo &goto :Next
 call "%~dp0..\%MyApplBase_TP%\03-BinPublic.ClientServer\ApplicationInfo.cmd" GetVerInfo
:Next

 rem -- 29.12.2014
 if not exist "%temp%" md "%temp%"

 Title "Start:%MyApplBase_TP%:[%JobMgr_VerFull%][%JobMgr_VerDateTime%] from:[%~dp0]"

 rem JobMgr_Root_DP Dir ermitteln !!JobMgr_Root_DP Name nicht aendern!! siehe Entw: JS Settingsmanager
 call :Parse_PathCutLastDir "%~dp0" JobMgr_Root_DP


 rem new 22.04.2013 J.Fes
 if /I "%JobMgr_Root_DP:~-25%" equ "03-BinPublic.ClientServer" call :Parse_PathCutLastDir "%JobMgr_Root_DP%" JobMgr_Root_DP

 rem new 11.10.2012 Verzeichniss: %JobMgr_RootL_DP% verwenden wenn dieses als Umgebunsvariable bereits definiert ist
 rem setx JobMgr_RootL_DP C:\Programs\JobMgrL /M
 if not defined JobMgr_RootL_DP   goto :JobMgr_RootL_DP_usedefault
 if     exist "%JobMgr_RootL_DP%" goto :Next
 if not exist "%JobMgr_RootL_DP%" md "%JobMgr_RootL_DP%"
 if     exist "%JobMgr_RootL_DP%" goto :Next


:JobMgr_RootL_DP_usedefault
 rem temp umbiegen
 rem angepasst 16.07.2009
 rem Step zunächst umbiegen nach %SystemDrive%\tmp
 set JobMgr_RootL_DP=%SystemDrive%\tmp
 set JobMgr_RootL_DP=%SystemDrive%\temp
 if not exist "%JobMgr_RootL_DP%" md "%JobMgr_RootL_DP%">nul
 if     exist "%JobMgr_RootL_DP%" md  "%JobMgr_RootL_DP%\JM$$TEMP$$TESTDIR">nul
 if     exist "%JobMgr_RootL_DP%\JM$$TEMP$$TESTDIR" rd /S /Q "%JobMgr_RootL_DP%\JM$$TEMP$$TESTDIR">nul& goto :Next
 if exist "%SystemDrive%\temp" set JobMgr_RootL_DP=%SystemDrive%\temp
 rem 24.09.2011 wenn kein anderes Verzeichniss verfuegbar dann User Temp verwenden
 if not exist "%JobMgr_RootL_DP%" set JobMgr_RootL_DP=%temp%
 goto :Next

:Next
 rem 12.12.2013/J.Fes Autogenerate: 03-BinPublic.Custom\JobManagerStartCustom.cmd
 rem 10.09.2014/J.Fes verlagert in JobManagerServiceTools_Start.cmd
 if exist "%JobMgr_Root_DP%\03-BinPublic.Custom\JobManagerStartCustom.cmd" call "%JobMgr_Root_DP%\03-BinPublic.Custom\JobManagerStartCustom.cmd" %*

:Next
 set temp_user=%temp%
 set temp=%JobMgr_RootL_DP%

 rem 23.05.2018&J.Fes add for development
 if /i "%~1" equ "/JobMgr_RootL_DP_get" goto :eof

 rem --- 01-BinServer ------------------
 rem !!JobMgr_01-BinServer_DP Name nicht aendern!! siehe Entw: JS Settingsmanager
 set JobMgr_01-BinServer_DP=%~dp0
 set JobMgr_01-BinServer_DP=%JobMgr_01-BinServer_DP:~0,-1%
 set JobMgr_BinPublicClientServer_DP=%JobMgr_01-BinServer_DP%\..\03-BinPublic.ClientServer

 rem new 21.04.09 J.Fes Var %JobMgr_01-BinServer_PLast% beinhaltet den TopRoot Path von 01-BinServer
 call :Parse_PLast %JobMgr_01-BinServer_DP% JobMgr_01-BinServer_PLast JobMgr_01-BinServer_PLast

 rem - bestimmen JobMgr_01-BinServerL_DP nach %temp% legen
 rem Locale Dirs festlegen

 set JobMgr_01-BinServerL_DP=%temp%\%MyApplBase_TP%\%JobMgr_01-BinServer_PLast%%JobMgr_VerNumLdir%

 rem 01-BinServer.Custom festlegen
 set JobMgr_ServerSetting_DP=%JobMgr_Root_DP%\01-BinServer.Custom
 set JobMgr_ClientSetting_DP=%JobMgr_Root_DP%\02-BinClient.Custom
REM  set PLMPerf_Setting_DP=%JobMgr_Root_DP%\01-PLMPerf.Custom

 rem --- 02-BinClient ----------------------------------------------------------
 rem JobMgr_02-BinClient_DP=.. new 21.04.09 angepasst 19.10.09 J.Fes damit 02-BinClient.ENTW wie 01-BinServer.ENTW (=TP) wird
 set JobMgr_02-BinClient_DP=%JobMgr_01-BinServer_DP:01-BinServer=02-BinClient%
 rem new 21.04.09 J.Fes Var %JobMgr_01-BinServer_PLast% beinhaltet den TopRoot Path von 01-BinServer
 call :Parse_PLast %JobMgr_02-BinClient_DP% JobMgr_02-BinClient_PLast JobMgr_02-BinClient_PLast

 rem Locale Dirs festlegen
 set JobMgr_02-BinClientL_DP=%temp%\%MyApplBase_TP%\%JobMgr_02-BinClient_PLast%%JobMgr_VerNumLdir%

 rem --- 03-BinPublic ----------------------------------------------------------
 set JobMgr_03-BinPublic_DP=%JobMgr_Root_DP%\03-BinPublic
 set JobMgr_03-BinPublicCustom_DP=%JobMgr_Root_DP%\03-BinPublic.Custom

 rem --- 05-PLMPerf ------------------
 set PLMPerf_01-PLMPerfS_DP=%~dp0
 set PLMPerf_01-PLMPerfS_DP=%PLMPerf_01-PLMPerfS_DP:~0,-1%

 rem new 21.04.09 J.Fes Var %JobMgr_01-BinServer_PLast% beinhaltet den TopRoot Path von 01-BinServer
 call :Parse_PLast %PLMPerf_01-PLMPerfS_DP% PLMPerf_01-PLMPerf_PLast PLMPerf_01-PLMPerf_PLast
 rem Locale Dirs festlegen
 set PLMPerf_01-PLMPerfL_DP=%temp%\%MyApplBase_TP%\%PLMPerf_01-PLMPerf_PLast%%JobMgr_VerNumLdir%


 rem -- %JobMgr_Root_DP%;
 set path_org=%path%
 rem set path=%JobMgr_03-BinPublicCustom_DP%;%JobMgr_03-BinPublic_DP%;%JobMgr_01-BinServer_DP%;%JobMgr_02-BinClient_DP%;%Path%
 set path=%JobMgr_03-BinPublicCustom_DP%;%JobMgr_03-BinPublic_DP%;%Path%


 if /i "%~1"=="/Server"      goto :JobServer
 if /i "%~1"=="/JobServer"   goto :JobServer
 if /i "%~1"=="/JobPlaner"   goto :JobPlaner
 if /i "%~1"=="/Client"      goto :JobClient
 if /i "%~1"=="/JobClient"   goto :JobClient
 if /i "%~1"=="/JobMgrCmdTools_CBSettingsMgr" goto :JobMgrCmdTools_CBSettingsMgr
 if /i "%~1"=="/JobMgrCmdTools_DQSettingsMgr" goto :JobMgrCmdTools_DQSettingsMgr
 if /i "%~1"=="/PLMPerf"     goto :PLMPerf
 if /i "%~1"=="/Screenshot"  goto :Screenshot
 if /i "%~1"=="/JobMgrLocalRoot_Open"  goto :JobMgrLocalRoot_Open

 goto :JobMgrLocalRoot_Open

 echo --------------------------------------------------------------------------
 Echo Error in start script for starting PLMJobManager programms
 Echo %0
 Echo.
 Echo Start Parameters:
 Echo P1=%1 P2=%2 P3=%3 P4=%4 P5=%5 P6=%6 P7=%7 P8=%8 P9=%9
 Echo.
 Echo Error: missing valid parameter:!!
 Echo.
 Echo the first paramters must be one of the listed values:
 Echo  /JobServer Starts %MyApplBase_TP% Server
 Echo  /JobServer  Starts %MyApplBase_TP% Client
 Echo.
 pause

goto :End

:JobMgrLocalRoot_Open
 set toRun=start "" explorer.exe /e, "%JobMgr_RootL_DP%"
 %toRun%
 goto :End

rem ============================================================================
:JobServer
 rem ------------------------------------------------------------------------
 rem Funktion:
 rem  Starte den JobServer
 rem
 rem  Kopiert die Programme mit allen erf. Komponenten auf den den localen Rechner (JobServer.Exe).
 rem  Anschliessend wird diese lokal kopierter Stand gestartet.
 rem  Die einstellungen ServerSettingsXML_DPNE werden vom Server verwendet
 rem  Hinweis: die Parameter P2..Pn werden an das Programm übergeben
 rem           die Umgebunsvariabale JobMgr_ServerSetting_DP wird für die bestimmung des pfades für den Ablageort der Serversettings festgelegt

 rem das locale JobServer_PRG
 set JobServer_EXE_DPNE=%JobMgr_01-BinServerL_DP%\JobServer.exe


:StartProg

  cd /D %temp%\%MyApplBase_TP%

  rem remove all version direcotiers, where JobServer.exe can be deleted
  rem New 25.06.2019 S.Gueth
REM   FOR /D /r %%G in ("%JobMgr_01-BinServer_PLast%V*") DO (
REM     del "%%G\JobServer.exe" /f /q
REM     if not exist %%G\JobServer.exe rmdir /s /q "%%G"
REM   )

  
  rem umgestell auf Versions Verzeichnisse am 22.05.2012 J.Fes
  set toRun=robocopy "%JobMgr_01-BinServer_DP%" "%JobMgr_01-BinServerL_DP%" /mir /r:3 /w:1 /XD _svn .svn Resources Archiv
  Echo Update Local "%JobMgr_01-BinServerL_DP%"
  call %toRun%

  set toRun=robocopy "%JobMgr_01-BinServer_DP%\Progs" "%JobMgr_01-BinServerL_DP%\Progs" /mir /r:3 /w:1 /XD _svn .svn Resources Archiv
  Echo Update Local "%JobMgr_01-BinServerL_DP%\Progs"
  call %toRun%

  set toRun=copy "%JobMgr_BinPublicClientServer_DP%\JobManagerCmdTools_Resources\JobManager.CmdToolsLib*.*"  "%JobMgr_01-BinServerL_DP%\*.*"
  call %toRun%
  rem path setzen
  set path=%JobMgr_01-BinServerL_DP%;%JobMgr_03-BinPublic_DP%;%path_org%
  cd /D "%JobMgr_01-BinServerL_DP%"
  set toRun="%JobServer_EXE_DPNE%" %2 %3 %4 %5 %6 %7 %8 %9
  rem 20.02.2019/J.Fes add for compatiblity
  if defined StartAsService set JobMgr_StartAsService=%StartAsService%
  if defined JobMgr_StartAsService (
     call %toRun%
  ) else (
     start "%MyApplBase_TP%" /D%JobMgr_01-BinServerL_DP% %toRun%
  )
  set path=%Path_org%
goto :End

rem ============================================================================
:JobClient
 rem Funktion: Starte den JobServer
 rem neuer Client erstellt 06.07.2010 A.Becker J.Feuerstein

 rem das locale JobClient_PRG
 set JobClient_EXE_DPNE=%JobMgr_02-BinClientL_DP%\JobClient.exe


:StartProg

 cd /D %temp%\%MyApplBase_TP%

  rem remove all version direcotiers, where JobClient.exe can be deleted
  rem New 25.06.2019 S.Gueth
REM   FOR /D /r %%G in ("%JobMgr_02-BinClient_PLast%V*") DO (
REM     del "%%G\JobClient.exe" /f /q
REM     if not exist %%G\JobClient.exe rmdir /s /q "%%G"
REM   )
  

 set toRun=robocopy "%JobMgr_02-BinClient_DP%" "%JobMgr_02-BinClientL_DP%" /mir /r:3 /w:1 /XD _svn .svn Resources Archiv
 Call %toRun%
 rem /ServerSettingsXML "%ClientSettingsXML_DPNE%"
 set toRun="%JobClient_EXE_DPNE%" %2 %3 %4 %5 %6 %7 %8 %9
 rem 29.03.2017/J.Fes %JobMgr_02-BinClientL_DP% removed from path
 set path=%JobMgr_03-BinPublic_DP%;%path_org%
 cd /D "%JobMgr_02-BinClientL_DP%"
 rem 28.09.2012 J.Fes /I eingefuegt um zu erreichen das nur das default Environment beim Start vom JobClient gesetzt ist
 rem 08.10.2012 J.Fes /I wieder entnommen da es zu Fehlern bei den Prompts kommen kann wenn C:\Dokumente und Einstellungen\UserName\..
 rem 05.03.2019/S.Gueth add for compatiblity
 if defined StartAsService set JobMgr_StartAsService=%StartAsService%
 if defined JobMgr_StartAsService (
     call %toRun%
  ) else (
     start "JC V%JobMgr_VerFull%" /D%JobMgr_02-BinClientL_DP% %toRun%
 )
 set path=%Path_org%
 goto :End

rem ============================================================================
:JobPlaner
 rem Funktion:
 rem  Starte das Server Programm
 rem
 rem  Kopiert die Programme mit allen erf. Komponenten auf den den localen Rechner (JobServer.Exe).
 rem  Anschliessend wird diese lokal kopierter Stand gestartet.
 rem  Die einstellungen ServerSettingsXML_DPNE werden vom Server verwendet
 rem  Hinweis: die Parameter P2..Pn werden an das Programm übergeben
 rem           die Umgebunsvariabale JobMgr_ServerSetting_DP wird für die bestimmung des pfades für den Ablageort der Serversettings festgelegt

 rem das locale JobServer_PRG
 set JobPlaner_EXE_DPNE=%JobMgr_01-BinServerL_DP%\JobManager.OnDemand.exe

 rem kopiert das Programm auf den localen Rechner
 rem dies ist erforderliche da .NET.exe Programme nur mit besonderen einstellungen
 rem vom Netz aus gestartet werden dürfen
 if not exist "%JobPlaner_EXE_DPNE%" goto :StartProg

 :StartProg
  set toRun=robocopy "%JobMgr_01-BinServer_DP%" "%JobMgr_01-BinServerL_DP%" /mir /r:0 /w:0 /XD _svn .svn Resources
  %toRun%

  set toRun="%JobPlaner_EXE_DPNE%" %JobPlanerCmdOptions% %2 %3 %4 %5 %6 %7 %8 %9
  rem path setzen
  set path=%JobMgr_01-BinServerL_DP%;%JobMgr_03-BinPublic_DP%;%path_org%
  cd /D "%JobMgr_01-BinServerL_DP%"
  start "%MyApplBase_TP%" /D%JobMgr_01-BinServerL_DP% %toRun%
  set path=%Path_org%
goto :End
rem ============================================================================
:JobMgrCmdTools_CBSettingsMgr
 rem Funktion: Starte den JobServer
 rem neuer Client erstellt 22.03.2013 J.Feuerstein / S.Gueth

 rem das locale JobClient_PRG
 rem --- 03-BinPublic.ClientServer ---------------------------------------------
 set JobMgr_03-BinPublicClientServer_DP=%~dp0
 set JobMgr_03-BinPublicClientServer_DP=%JobMgr_03-BinPublicClientServer_DP:~0,-1%

 call :Parse_PLast %JobMgr_03-BinPublicClientServer_DP% JobMgr_03-BinPublicClientServer_PLast JobMgr_03-BinPublicClientServer_PLast
 set JobMgr_03-BinPublicClientServerL_DP=%temp%\%MyApplBase_TP%\03-BinPublic.ClientServer\%JobMgr_03-BinPublicClientServer_PLast%%JobMgr_VerNumLdir%

 rem in diesem Fall parse JobMgr_Root_DP ein Verz. tiefer
 call :Parse_PathCutLastDir "%~dp0\.." JobMgr_Root_DP
 set JobMgrCmdTools_CBSettingsMgr_EXE_DPNE=%JobMgr_03-BinPublicClientServerL_DP%\JobMgrCmdTools_CBSettingsMgr.exe

:StartProg
 set toRun=robocopy "%JobMgr_03-BinPublicClientServer_DP%" "%JobMgr_03-BinPublicClientServerL_DP%" /mir /r:3 /w:1 /XD _svn .svn Resources Archiv
 Call %toRun%

 set toRun="%JobMgrCmdTools_CBSettingsMgr_EXE_DPNE%" -JobMgr_Root_DP "%JobMgr_Root_DP%" %2 %3 %4 %5 %6 %7 %8 %9
 set path=%JobMgr_03-BinPublicClientServerL_DP%;%JobMgr_03-BinPublic_DP%;%path_org%
 cd /D "%JobMgr_03-BinPublicClientServerL_DP%"
 start "JobMgrCmdTools_CBSettingsMgr V%JobMgr_VerFull%" /D%JobMgr_03-BinPublicClientServerL_DP% %toRun%
 set path=%Path_org%
 goto :End

rem ============================================================================
:JobMgrCmdTools_DQSettingsMgr
 rem Funktion: Starte den DataQuality Settings manager

 rem das locale JobClient_PRG
 rem --- 03-BinPublic.ClientServer ---------------------------------------------
 set JobMgr_03-BinPublicClientServer_DP=%~dp0
 set JobMgr_03-BinPublicClientServer_DP=%JobMgr_03-BinPublicClientServer_DP:~0,-1%

 call :Parse_PLast %JobMgr_03-BinPublicClientServer_DP% JobMgr_03-BinPublicClientServer_PLast JobMgr_03-BinPublicClientServer_PLast
 set JobMgr_03-BinPublicClientServerL_DP=%temp%\%MyApplBase_TP%\03-BinPublic.ClientServer\%JobMgr_03-BinPublicClientServer_PLast%%JobMgr_VerNumLdir%

 rem in diesem Fall parse JobMgr_Root_DP ein Verz. tiefer
 call :Parse_PathCutLastDir "%~dp0\.." JobMgr_Root_DP

 set JobMgrCmdTools_CBSettingsMgr_EXE_DPNE=%JobMgr_03-BinPublicClientServerL_DP%\JobMgrCmdTools_DQSettingsMgr.exe

:StartProg
 set toRun=robocopy "%JobMgr_03-BinPublicClientServer_DP%" "%JobMgr_03-BinPublicClientServerL_DP%" /mir /r:3 /w:1 /XD _svn .svn Resources Archiv
 Call %toRun%

 set toRun="%JobMgrCmdTools_CBSettingsMgr_EXE_DPNE%" -JobMgr_Root_DP "%JobMgr_Root_DP%" %2 %3 %4 %5 %6 %7 %8 %9
 set path=%JobMgr_03-BinPublicClientServerL_DP%;%JobMgr_03-BinPublic_DP%;%path_org%
 cd /D "%JobMgr_03-BinPublicClientServerL_DP%"
 start "JobMgrCmdTools_DQSettingsMgr V%JobMgr_VerFull%" /D%JobMgr_03-BinPublicClientServerL_DP% %toRun%
 set path=%Path_org%
 goto :End


rem ============================================================================
:PLMPerf
 rem ------------------------------------------------------------------------
 rem Funktion:
 rem  Starte das PLMPerformance Analyse Program
 rem  erstellt 26.11.2012 14:10 S.Gueth J.Feuerstein

 rem das locale PDMPerf_PRG
 set PLMPerformanceAnalyse_exe_DPNE=%PLMPerf_01-PLMPerfL_DP%\PLMPerformanceAnalyse.exe

 rem die PDMPerf Settings immer vom Server
REM  if not exist "%PLMPerf_Setting_DP%" md "%PLMPerf_Setting_DP%"
REM  set SettingsGlobal_DPNE=%PLMPerf_Setting_DP%\PDMPerf_SettingsGlobal.xml
REM  if not exist "%SettingsGlobal_DPNE%" copy "%PLMPerf_01-PLMPerfS_DP%\SettingsGlobal.xml" "%SettingsGlobal_DPNE%"

:StartProg
 set toRun=robocopy "%PLMPerf_01-PLMPerfS_DP%" "%PLMPerf_01-PLMPerfL_DP%" /mir /r:3 /w:1 /XD _svn .svn Resources Archiv
 Call %toRun%

 set toRun="%PLMPerformanceAnalyse_exe_DPNE%" %2 %3 %4 %5 %6 %7 %8 %9
 set path=%PLMPerf_01-PLMPerfL_DP%;%JobMgr_03-BinPublic_DP%;%path_org%
 cd /D "%PLMPerf_01-PLMPerfL_DP%"

 Echo start "PLMPerf V%JobMgr_VerFull%" /D%PLMPerf_01-PLMPerfL_DP% %toRun%
 rem 05.03.2019/S.Gueth add for compatiblity
 if defined StartAsService set JobMgr_StartAsService=%StartAsService%
 if defined JobMgr_StartAsService (
     call %toRun%
  ) else (
     start "PLMPerf V%JobMgr_VerFull%" /D%PLMPerf_01-PLMPerfL_DP% %toRun%
  )
 

 set path=%Path_org%
 goto :End

:End
 goto :eof

rem ============================================================================
:Screenshot
 rem ------------------------------------------------------------------------
 rem Funktion:
 rem  Starte das Screenshot Program
 rem  erstellt 05.09.2013 10:35 J.Feuerstein
 setlocal

   rem #Doc: Settings are defined in  %ScreenShotS_DP%\Greenshot.ini
   rem 05.09.2013 GreenShot Start Params
   REM /help   This help.
   REM /exit   Tries to close all running instances.
   REM /reload Reload the configuration of Greenshot.
   REM /language [language code] Set the language of Greenshot, e.g. greenshot /language en-US. de-DE
   REM [filename] Open the bitmap files in the running Greenshot instance or start a new instance
   @echo off

   rem aktive Sparache herausfinden
   set language_use=de-DE
   FOR /F "tokens=3 delims= " %%G in ('reg query "hklm\system\controlset001\control\nls\language" /v Installlanguage') DO (IF "%%G" NEQ "0407" set language_use=en-US)

   set ScreenShotS_DP=%JobMgr_03-BinPublic_DP%\Greenshot
   set ScreenShotData_DP=%JobMgr_Root_DP%\11-Documentation.Custom\zzScreenShots
   if not exist "%ScreenShotData_DP%" Echo I: Create ScreenShotData_DP:"%ScreenShotData_DP%"& md "%ScreenShotData_DP%"

   rem Locale Dirs festlegen
   set ScreenshotL_DP=%temp%\%MyApplBase_TP%\03-BinPublic\Greenshot
   set ScreenshotL_DPNE=%temp%\%MyApplBase_TP%\03-BinPublic\Greenshot\Greenshot.exe

   set toRun=robocopy "%ScreenShotS_DP%" "%ScreenshotL_DP%" /mir /r:3 /w:1 /XD _svn .svn Resources Archiv /xf unins000*.*
   Call %toRun%
   start "" /D%ScreenShotData_DP% %ScreenshotL_DPNE% /language %language_use%

 endlocal
 goto :eof


rem ##### ------------ Standard Subroutines --------------------- ######
:DateTimeNowGet
 rem call :DateTimeNowGet
 rem Set File_LPNE=%DatRoot_DP%\MyName-%DateTimeNowFileExt%.txt


 if     "%time:~0,1%"==" " set time-h=0%time:~1,1%
 if not "%time:~0,1%"==" " set time-h=%time:~0,2%

 if     "%time:~3,1%"==" " set time-m=0%time:~4,1%
 if not "%time:~3,1%"==" " set time-m=%time:~3,2%

 set Date-Y=%Date:~6,4%
 set Date-M=%Date:~3,2%
 set Date-D=%Date:~0,2%
 set DateTimeNowFileExt=%Date-Y%-%Date-M%-%Date-D%-%time-h%-%time-m%
 goto :eof


:Parse_All
 rem parst alle File Bezeichner aus
 rem "\" abschneiden
 set Parse_all$temp=%~dp1
 set Parse_all$temp=%Parse_all$temp:~0,-1%
 call :Parse_PLast %Parse_all$temp% %2_PLast %2_PLast2
 call :Parse_PathCutLastDir %~dp0 %2_DPnoPLast
 set %2_DP=%Parse_all$temp%
 set %2_D=%~d1
 rem "\" hinten und vorne abschneiden
 set Parse_all$temp=%~p1
 set Parse_all$temp=%Parse_all$temp:~1,-1%
 set %2_P=%Parse_all$temp%
 set %2_NE=%~nx1
 set %2_N=%~n1
 set %2_E=%~x1
 set %2_DPNE=%1
 set %2_DPN=%~dpn1
 set Parse_all$temp=
 goto :eof

:Parse_PLast
 rem parst den LetzenPath
 set %2=%~n1
 set %3=%~nx1
 goto :eof


:Parse_PathCutLastDir
 rem schneidet das letzte Verzeichniss Uebergeben path ab
 rem P1 = Name der Variablen
 rem P2 = der Übergebene Path
 rem Example : call :Parse_PathCutLastDir %~dp0 EntwRoot_DP
 rem Example : call :Parse_PathCutLastDir %~dp0 MyVar_DP

 set PathCutLastDir$temp=%1
 set PathCutLastDir$temp=%PathCutLastDir$temp:"=%

 set PathCutLastDir$tempLastChar=%PathCutLastDir$temp:~-1%
 set PathCutLastDir$tempNoBacks=%PathCutLastDir$temp:~0,-1%

 if "%PathCutLastDir$tempLastChar%"=="\" (
   rem "\" abschneiden wenn vorhanden
   call :PathCutLastDirDo PathCutLastDir$tempRes %PathCutLastDir$tempNoBacks%
 ) else (
   rem
   call :PathCutLastDirDo PathCutLastDir$tempRes %PathCutLastDir$temp%
 )
 set PathCutLastDir$tempRes=%PathCutLastDir$tempRes:~0,-1%
 set %2=%PathCutLastDir$tempRes%
 set PathCutLastDir$temp=
 set PathCutLastDirDo$temp1=
 set PathCutLastDir$tempNoBacks=
 set PathCutLastDir$tempNoLastChar=
 set PathCutLastDir$tempLastChar=
 set PathCutLastDir$tempRes=
 goto :eof

:PathCutLastDirDo
 rem hiermit schneiden wir den Path ab
 rem echo.
 rem Echo P1=%1 P2=%2
 set PathCutLastDirDo$temp=%~dp2
 rem "\" abschneiden
 set PathCutLastDirDo$temp1=%PathCutLastDir$temp:~0,-1%
 set %1=%PathCutLastDirDo$temp%
 set PathCutLastDirDo$temp=
 set PathCutLastDirDo$temp1=
 goto :eof
