Advertisement
J2897

TightVNC PuTTY Tunnel

Sep 14th, 2016
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.44 KB | None | 0 0
  1. :: Released under the GNU General Public License version 3+ by J2897.
  2.  
  3. @echo OFF
  4. setlocal
  5. pushd "%~dp0"
  6.  
  7. REM #################### README #################### > BEGIN
  8. :: Filename:    desktop.bat
  9. :: Version:     1.0
  10. :: Latest:      http://pastebin.com/3yuEKqUf
  11. :: Contact:     https://pastebin.com/message_compose?to=J2897
  12. ::
  13. :: This script is for launching TightVNC via a PuTTY SSH tunnle. It assumes
  14. :: that the TightVNC file is named the same as the saved PuTTY session.
  15. ::
  16. :: Example...
  17. :: PuTTY session name: PC1-W7
  18. :: TightVNC file name: C:\Users\%USERNAME%\VNC\PC1-W7.vnc
  19. ::
  20. :: Simply pass the name as a parameter...
  21. :: C:\folder\desktop.bat PC1-W7
  22. ::
  23. :: Now you can create as many shortcuts as you like to quickly connect to
  24. :: each desktop securely.
  25. ::
  26. :: Note that spaces and special characters are not supported. Rename them.
  27. REM #################### README #################### > END
  28.  
  29. REM Get port from VNC file.
  30. for /f "tokens=1,2 delims==" %%A in (%USERPROFILE%\VNC\%1.vnc) do (
  31.     if "%%A" == "port" (set PORT=%%B)
  32. )
  33.  
  34. REM Start PuTTY session.
  35. start "" /MIN "%PROGRAMFILES%\PuTTY\putty.exe" -load "%1"
  36.  
  37. REM Wait for port to listen.
  38. set CHECKS=0
  39. :Check
  40. netstat -a -p TCP |find "%PORT%" |find "LISTENING" >nul
  41. if errorlevel 1 (
  42.     set /a CHECKS+=1
  43.     if %CHECKS% EQU 30 (
  44.         echo TCP port %PORT% is not listening.
  45.         pause
  46.         goto :End
  47.     )
  48.     goto :Check
  49. )
  50.  
  51. REM Connect to desktop.
  52. start "" "%USERPROFILE%\VNC\%1.vnc"
  53.  
  54. :End
  55. endlocal
  56. popd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement