@Echo off
rem Script for Control Connetion via RemoteDesktop
rem 31.10.2012 J.Fes addPLM - JF
rem 25.07.2014 J.Fes addPLM - JF Update
rem 22.12.2014 J.Fes addPLM - Update after reorg 01-BinServer.Custom


set Client_ComputerName=#JobComputers_tbl.ComputerName#
set Client_ComputerFQDN=#JobComputers_tbl.ComputerFQDN#
set OsUser=#JobComputers_tbl.OsUser#
if "%Client_ComputerFQDN%" equ "" set Client_ComputerFQDN=%Client_ComputerName%

REM set MyAppData_Root_DP=%AppData%\JobManager
set MyAppData_Root_DP=%~dp0..\..\..\..\01-BinServer.Custom\Computers\%ComputerName%\Remote\%UserName%
set MyAppData_Setting_DPNE=%MyAppData_Root_DP%\%Client_ComputerName%_LastUsedRDP.cmd
set Rdp_DPNE=%MyAppData_Root_DP%\%Client_ComputerName%.rdp

if not exist "%MyAppData_Root_DP%" md  "%MyAppData_Root_DP%"
set doNext=

set 20-JobComputerScripts_DP=#20-JobComputerScripts_DP#
set 01-BinServer_DP=#01-BinServer_DP#
set 02-BinClient_DP=#02-BinClient_DP#
set 03-BinPublic_DP=#03-BinPublic_DP#
set 04-Templates_DP=#04-Templates_DP#
set 10-Doku_DP=#10-Doku_DP#
set 90-DATA_DP=#90-DATA_DP#
set S_Root_DP=#00-ApplRoot_DP#

rem Titelzeile schreiben
 title Stop Processes on:[\\%Client_ComputerName%]
REM  Echo -----------------------------------------------------------------------
REM  Echo Stop Processes on.....: %Client_ComputerName%
REM  call :TaskListDo
REM  call :TaskKillDo
REM  timeout /T:3
REM  Echo -----------------------------------------------------------------------


:Menue
 color E0

  if /I "%Client_ComputerName%" neq "%ComputerName%" goto :jumbOver
    Echo -----------------------------------------------------------------------
    color C0
    Echo Info: You try to create a self referencing remote connection
    Echo on the computer you are currently working with [\\%Client_ComputerName%]
    Echo.
    Echo after pressing return key process ends
    pause
    Exit /b
    Echo -----------------------------------------------------------------------
 :jumbOver


 rem set Defaults
 if exist "%MyAppData_Setting_DPNE%" call "%MyAppData_Setting_DPNE%"
 if not defined doNext set doNext=B


 Echo.
 Echo --------------------------------------------------------------------------
 Echo Settings are stored in: '%MyAppData_Setting_DPNE%'
 Echo --------------------------------------------------------------------------
 Echo Stop Processes on.....: %Client_ComputerName%
 Echo.
 Echo  P  = Ping: %Client_ComputerName%
 Echo  B =  Reboot %Client_ComputerName% via Remote shutdown /M %Client_ComputerName%
 Echo.
 Echo  S =  Stop Banner
 Echo  L =  List tasks
 Echo  Q  = Quit (end this menue)
 Echo.
 Echo please select next function:
 set /P doNext=or function Default:[%doNext%] :

 if /I "%doNext%" neq "" if /I "%doNext%" neq "?" if /I "%doNext%" neq "Q" Echo set doNext=%doNext%>"%MyAppData_Setting_DPNE%"
 Color A0
 if /I "%doNext%"=="Q"    Exit

 Echo.
 Echo --------------------------------------------------------------------------
 Echo.
 if /I "%doNext%"=="S"  call :TaskKillDo
 if /I "%doNext%"=="B"  call :BootRemote

 if /I "%doNext%"=="L"  call :TaskListDo
 if /I "%doNext%"=="P"  call :Ping
 goto :Menue

:TaskKillDo
   call taskkill /S %Client_ComputerName% /FI "IMAGENAME eq banner*"
 goto :eof

:TaskListDo
   Echo -------- Tasklist banner --------------------
   call tasklist /S %Client_ComputerName% /FI "IMAGENAME eq banner*"
   Echo -------- Tasklist j* --------------------
   call tasklist /S %Client_ComputerName% /FI "IMAGENAME eq j*"
   Echo -------- Tasklist /APPS --------------------
   call tasklist /S %Client_ComputerName% /APPS
 goto :eof

:BootRemote
  Echo -------- DO: Reboot Host \\%Client_ComputerName% -----------------------
  Call shutdown /F /r /c "JobClient needed to be rebooted via shutdown /M \\%Client_ComputerName%" /M \\%Client_ComputerName%
  pause
 goto :eof

rem - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
:Ping
 Echo.
 Echo --------------------------------------------------------------------------
 Echo Ping \\%Client_ComputerName%
 Ping %Client_ComputerName%
 Echo --------------------------------------------------------------------------
 goto :eof

