@Echo off

setlocal
 rem Script for connection to JobClient via UltraVNC
 set CurCmdRoot_DP=%~dp0
 set CurCmdRoot_DP=%CurCmdRoot_DP:~0,-1%

 call :PathCutLastDir S_Root_DP %~dp0
 set Path=%S_Root_DP%\03-BinPublic;%S_Root_DP%\03-BinPublic\UltraVnc;%Path%

 set Client_ComputerName=%1
 rem Titelzeile schreiben
 title RemoteControl connect via UltraVnc to:[\\%Client_ComputerName%]
 if not "%Client_ComputerName%"=="" start " " "%S_Root_DP%\03-BinPublic\UltraVnc\vncviewer.exe" -shared -scale 8/10 -64colors %*
 if     "%Client_ComputerName%"=="" start " " "%S_Root_DP%\03-BinPublic\UltraVnc\vncviewer.exe" 

goto :Ende

rem ##### ------------ Standard Subroutines --------------------- ######
:PathCutLastDir
 rem schneidet das letzte Verzeichniss Uebergeben path ab
 rem P1 = Name der Variablen
 rem P2 = der Übergebene Path
 rem Example : call :PathCutLastDir EntwRoot_LP %~dp0
 rem Example : call :PathCutLastDir MyVar %~dp0

 set PathCutLastDir$temp=%2
 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 %1=%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

:ErrExit
 call :Echo ---------------------------------------
 call :Echo Error up in:
 call :Echo %0
 call :Echo please check your Logfile
 call :Echo %Log_DPNE%
 Pause
 goto :eof

:Ende

endlocal
