Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :: Released under the GNU General Public License version 3+ by J2897.
- @echo OFF
- setlocal
- pushd "%~dp0"
- REM #################### README #################### > BEGIN
- :: Filename: desktop.bat
- :: Version: 1.0
- :: Latest: http://pastebin.com/3yuEKqUf
- :: Contact: https://pastebin.com/message_compose?to=J2897
- ::
- :: This script is for launching TightVNC via a PuTTY SSH tunnle. It assumes
- :: that the TightVNC file is named the same as the saved PuTTY session.
- ::
- :: Example...
- :: PuTTY session name: PC1-W7
- :: TightVNC file name: C:\Users\%USERNAME%\VNC\PC1-W7.vnc
- ::
- :: Simply pass the name as a parameter...
- :: C:\folder\desktop.bat PC1-W7
- ::
- :: Now you can create as many shortcuts as you like to quickly connect to
- :: each desktop securely.
- ::
- :: Note that spaces and special characters are not supported. Rename them.
- REM #################### README #################### > END
- REM Get port from VNC file.
- for /f "tokens=1,2 delims==" %%A in (%USERPROFILE%\VNC\%1.vnc) do (
- if "%%A" == "port" (set PORT=%%B)
- )
- REM Start PuTTY session.
- start "" /MIN "%PROGRAMFILES%\PuTTY\putty.exe" -load "%1"
- REM Wait for port to listen.
- set CHECKS=0
- :Check
- netstat -a -p TCP |find "%PORT%" |find "LISTENING" >nul
- if errorlevel 1 (
- set /a CHECKS+=1
- if %CHECKS% EQU 30 (
- echo TCP port %PORT% is not listening.
- pause
- goto :End
- )
- goto :Check
- )
- REM Connect to desktop.
- start "" "%USERPROFILE%\VNC\%1.vnc"
- :End
- endlocal
- popd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement