::----------------------------------------
:: start SSH and then connect to remote desktop
:: written by: chris sawall
:: written on: 14 July 2003
:: last modified: 21 August 2003
::
:: HOWTO configure remote desktop to 
:: connect on a specific port -->
:: http://support.microsoft.com/default.aspx?scid=kb;en-us;304304
::
:: HOWTO configure remote desktop to 
:: listen on a specific port -->
:: http://support.microsoft.com/default.aspx?scid=kb;en-us;306759
::
:: HOWTO Setup Remote Desktop to allow connection
:: from localhost -->
:: http://www.bitvise.com/remote-desktop.html
::
:: If wait.exe is not on system, download from
:: http://www.simtel.net/pub/dl/40696.html
::
::----------------------------------------
@echo off
::****************************************
:: USER DEFINED VARIABLES
::****************************************
::----------------------------------------
:: set TIME equal to the number of seconds
:: to wait between logging in and starting
:: remote desktop.
::
:: for PATH information, be sure to
:: finish PATH with a trailing backslash (\)
::----------------------------------------
set TIME=15
set PUTTY=putty.exe
set PUTTYDIR=c:\rdp\
set RDP=mstsc.exe
set RDPDIR=c:\rdp\
set USERNAME=JoeUser
set SSHLPORT=3390
set DESTINATIONPC=10.x.x.x
set DESTINATIONPORT=7724
::----------------------------------------
:: set PUTTY variables
::----------------------------------------
set SSHSERVER=SSHSERVER.IP.ADDRESS.HERE
set SSHPORT=5525
::----------------------------------------
:: set WAIT variable
:: set WAIT to LOCAL if using existing wait.exe
:: set WAIT to SIMTEL if downloaded from Simtel
:: if WAIT is set to SIMTEL, be sure to set the
:: WAITEXE to the newly download exe file.
::----------------------------------------
set WAIT=SIMTEL
set WAITDIR=c:\rdp\wait\
set WAITEXE=wait.exe
::****************************************
:: END - USER DEFINED VARIABLES
:: do not change any lines below here
:: batch file may not work properly
::****************************************
::----------------------------------------
:: set PUTTY executable
::----------------------------------------
set PUTTYEXE=%PUTTYDIR%%PUTTY%
::----------------------------------------
:: start PUTTY
::----------------------------------------
start %PUTTYEXE% -ssh -P %SSHPORT% -l %USERNAME% -L %SSHLPORT%:%DESTINATIONPC%:%DESTINATIONPORT% %SSHSERVER%
@echo PuTTY started...
@echo.
::----------------------------------------
:: determine WAIT variable and start accordingly
::----------------------------------------
if "%WAIT%" == "LOCAL" (
	goto :main
	)
if "%WAIT%" == "SIMTEL" (
	goto :simtel
	)
:main
for /L %%i IN (0,1,%TIME%) DO call :local %%i
::----------------------------------------
:: If WAIT = LOCAL
::----------------------------------------
:local
set CURRENT=%1
set /A VAR=%TIME%-%CURRENT%
::cls
if /i %VAR%==0 goto startRDP
@echo Waiting for %VAR% more seconds
wait 1
goto done
::----------------------------------------
:: If WAIT = SIMTEL
::----------------------------------------
:simtel
%WAITDIR%%WAITEXE% %TIME%
goto startRDP
::----------------------------------------
:: start Remote Desktop session
::----------------------------------------
:startRDP
set RDPEXE=%RDPDIR%%RDP%
start "Remote Desktop Session" %RDPEXE% /v:localhost:%SSHLPORT%
@echo.
@echo Remote Desktop has been started...
@echo.
goto end

:end
echo Press any key to close this window.
pause > nul
exit 

:done