@Echo off
rem Script for Control Connetion via RemoteDesktop
rem 31.10.2012 J.Fes addPLM - JF

REM setlocal


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\%ComputerName%_%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 RDP connect via:[\\%Rdp_DPNE%]

: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


 set S1_W=1024& set S1_H=768
 set M1_W=1200& set M1_H=840
 set L1_W=1767& set L1_H=1100
 set L2_W=1680& set L2_H=1050
 set L3_W=1920& set L3_H=1200
 set R_SPAN=/span
 set R_Full=/f

 rem set Defaults
 if exist "%MyAppData_Setting_DPNE%" call "%MyAppData_Setting_DPNE%"
 if not defined doNext set doNext=RL
 if not defined res    set R_W=%M1_W%  & set R_H=%M1_H%

 Echo.
 Echo --------------------------------------------------------------------------
 Echo Connect Remote via RDP to:%Client_ComputerName%
 Echo.
 Echo  P  = Ping: %Client_ComputerName%
 Echo  FL = Flush DNS via Iponfig
 Echo.
 Echo  S  = W:[%S1_W%]   H:[%S1_H%] small
 Echo  M  = W:[%M1_W%]   H:[%M1_H%] middel
 Echo  L1 = W:[%L1_W%]   H:[%L1_H%] large 1
 Echo  L2 = W:[%L2_W%]   H:[%L2_H%] large 2
 Echo  L3 = W:[%L3_W%]   H:[%L3_H%] large 3
 Echo.
 Echo  SP = W:[%R_SPAN%] use win span mode
 Echo  F  = W:[%R_Full%] use win full mode
 Echo  E  = use Rdp File /Edit
 Echo.      %Rdp_DPNE:~-60%
 Echo.
 Echo  Q  = Quit (end this menue)
 Echo.
 Echo please select the resolution you would like to use:
 set /P doNext=or function Default:[%doNext%] :

 if /I "%doNext%" neq "" if /I "%doNext%" neq "?" if /I "%doNext%" neq "Q" if /I "%doNext%" neq "FL" if /I "%doNext%" neq "P"    Echo set doNext=%doNext%>"%MyAppData_Setting_DPNE%"
 Color A0
 if /I "%doNext%"=="Q"    Exit
 if /I "%doNext%"=="S"    set R_W=%S1_W%&  set R_H=%S1_H%&  call :RemoteDesktop
 if /I "%doNext%"=="M"    set R_W=%M1_W%&  set R_H=%M1_H%&  call :RemoteDesktop
 if /I "%doNext%"=="L1"   set R_W=%L1_W%&  set R_H=%L1_H%&  call :RemoteDesktop
 if /I "%doNext%"=="L2"   set R_W=%L2_W%&  set R_H=%L2_H%&  call :RemoteDesktop
 if /I "%doNext%"=="L3"   set R_W=%L3_W%&  set R_H=%L3_H%&  call :RemoteDesktop
 if /I "%doNext%"==""     set R_W=%L1_W%&  set R_H=%L1_H%&  call :RemoteDesktop
 if /I "%doNext%"=="SP"   call :RemoteDesktop /span
 if /I "%doNext%"=="F"    call :RemoteDesktop /f
 if /I "%doNext%"=="E"    call :RemoteDesktop /edit
 if /I "%doNext%"=="EE"   start Explorer /e, "%MyAppData_Root_DP%"
 if /I "%doNext%"=="?"    start "RDP" mstsc.exe /?
 if /I "%doNext%"=="P"    Call :Ping
 if /I "%doNext%"=="FL"   Call :IpConfig "/displaydns"& Call :IpConfig "/FlushDns"& Call :IpConfig "/displaydns"
 goto :Menue


rem - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
:RDP_FileGen
 rem Geeriert den RDP File
 set /a winpos_x2=%R_W% + 50
 set /a winpos_y2=%R_H% + 50
 Echo screen mode id:i:1 >>"%Rdp_DPNE%"
 Echo desktopwidth:i:%R_W% >>"%Rdp_DPNE%"
 Echo desktopheight:i:%R_H% >>"%Rdp_DPNE%"
 Echo session bpp:i:15 >>"%Rdp_DPNE%"
 Echo winposstr:s:0,1,0,0,%winpos_x2%,%winpos_y2% >>"%Rdp_DPNE%"
 Echo full address:s:%Client_ComputerName% >>"%Rdp_DPNE%"
 Echo compression:i:1 >>"%Rdp_DPNE%"
 Echo keyboardhook:i:2 >>"%Rdp_DPNE%"
 Echo audiomode:i:0 >>"%Rdp_DPNE%"
 Echo redirectdrives:i:1 >>"%Rdp_DPNE%"
 Echo redirectprinters:i:0 >>"%Rdp_DPNE%"
 Echo redirectcomports:i:0 >>"%Rdp_DPNE%"
 Echo redirectsmartcards:i:0 >>"%Rdp_DPNE%"
 Echo displayconnectionbar:i:1 >>"%Rdp_DPNE%"
 Echo autoreconnection enabled:i:1 >>"%Rdp_DPNE%"
 Echo username:s:%OsUser% >>"%Rdp_DPNE%"
REM  Echo domain:s: >>"%Rdp_DPNE%"
 Echo alternate shell:s: >>"%Rdp_DPNE%"
 Echo shell working directory:s: >>"%Rdp_DPNE%"
 Echo disable wallpaper:i:1 >>"%Rdp_DPNE%"
 Echo disable full window drag:i:1 >>"%Rdp_DPNE%"
 Echo disable menu anims:i:1 >>"%Rdp_DPNE%"
 Echo disable themes:i:1 >>"%Rdp_DPNE%"
 Echo disable cursor setting:i:0 >>"%Rdp_DPNE%"
 Echo bitmapcachepersistenable:i:1 >>"%Rdp_DPNE%"
 Echo use multimon:i:0 >>"%Rdp_DPNE%"
 Echo audiocapturemode:i:0 >>"%Rdp_DPNE%"
 Echo videoplaybackmode:i:1 >>"%Rdp_DPNE%"
 Echo connection type:i:1 >>"%Rdp_DPNE%"
 Echo allow font smoothing:i:0 >>"%Rdp_DPNE%"
 Echo allow desktop composition:i:0 >>"%Rdp_DPNE%"
 Echo redirectclipboard:i:1 >>"%Rdp_DPNE%"
 Echo redirectposdevices:i:0 >>"%Rdp_DPNE%"
 Echo redirectdirectx:i:1 >>"%Rdp_DPNE%"
 Echo drivestoredirect:s:* >>"%Rdp_DPNE%"
 Echo authentication level:i:2 >>"%Rdp_DPNE%"
 Echo prompt for credentials:i:0 >>"%Rdp_DPNE%"
 Echo negotiate security layer:i:1 >>"%Rdp_DPNE%"
 Echo remoteapplicationmode:i:0 >>"%Rdp_DPNE%"
 Echo gatewayhostname:s: >>"%Rdp_DPNE%"
 Echo gatewayusagemethod:i:4 >>"%Rdp_DPNE%"
 Echo gatewaycredentialssource:i:4 >>"%Rdp_DPNE%"
 Echo gatewayprofileusagemethod:i:0 >>"%Rdp_DPNE%"
 Echo promptcredentialonce:i:1 >>"%Rdp_DPNE%"
 Echo use redirection server name:i:0 >>"%Rdp_DPNE%"
 goto :eof

rem -- Start RDP via mstsc.exe -------------------------------------------------
:RemoteDesktop

 set toRun=
 if /i "%1" neq "/f" goto :JumpOver
  if not exist "%Rdp_DPNE%" call :RDP_FileGen
  set toRun=start "RDP" mstsc.exe "%Rdp_DPNE%" /f
  Echo %toRun%
  %toRun%
  exit
 :JumpOver

 if /i "%1" neq "/span" goto :JumpOver
  if not exist "%Rdp_DPNE%" call :RDP_FileGen
  set toRun=start "RDP" mstsc.exe "%Rdp_DPNE%" /span
  Echo %toRun%
  %toRun%
  exit
 :JumpOver

 if /i "%1" neq  "/edit" goto :JumpOver
    if not exist "%Rdp_DPNE%" call :RDP_FileGen
    set toRun=start "RDP" mstsc.exe /edit "%Rdp_DPNE%"
    %toRun%
 :JumpOver

 if /i "%toRun%" neq "" goto :JumpOver
    call :RDP_FileGen
    set toRun=start "RDP" mstsc.exe "%Rdp_DPNE%"
    %toRun%
    exit
 :JumpOver

 if /i "%toRun%" neq  "" goto :JumpOver
    set toRun=start "RDP" mstsc.exe /V:%Client_ComputerFQDN% %Res%
    %toRun%
    exit
 :JumpOver
 goto :eof

rem - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
:Ping
 Echo.
 Echo --------------------------------------------------------------------------
 Echo Ping \\%Client_ComputerName% FQDN=[%Client_ComputerFQDN%]
 Ping %Client_ComputerFQDN%
 Echo --------------------------------------------------------------------------
 goto :eof

rem - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
:IpConfig
 set IpConfig_opt=%~1
 Echo.
 Echo --------------------------------------------------------------------------
 Echo ipconfig %IpConfig_opt% on \\%ComputerName%
 ipconfig %IpConfig_opt%
 Echo --------------------------------------------------------------------------
 pause
 goto :eof
:Ende
endlocal
