Created
June 21, 2017 09:36
-
-
Save g3rhard/cc2291371001de46e909385af64da3a7 to your computer and use it in GitHub Desktop.
Bat script for reconnect VPN connection in Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:loop | |
echo testing IP address | |
ping 123.456.78.90 >nul || ( | |
echo ping failure - disconnecting | |
rasdial name_of_your_vpn_connect /disconnect | |
timeout /t 10 /nobreak | |
echo reconnecting | |
rasdial name_of_your_vpn_connect | |
timeout /t 10 /nobreak | |
) | |
timeout /t 30 /nobreak | |
goto :loop |
Hello from 2020 =)
A little improved version:
@echo off
set VPN=Your_VPN_Name
set USERNAME=Your_VPN_User_Name
set PASSWORD=Your_VPN_Password
:loop
cls
echo Checking connection availability...
ipconfig|find /i "%VPN%"
if %errorlevel%==1 goto:reconnect
timeout /t 30 /nobreak
goto :loop
:reconnect
echo Disconnecting...
rasdial "%VPN%" /disconnect
timeout /t 10 /nobreak
echo Connecting...
rasdial "%VPN%" "%USERNAME%" "%PASSWORD%"
timeout /t 10 /nobreak
goto :loop
This version checking existing ipconfig adapter connection to detect current VPN connection
@picolino, thank you, good job!
excellent job @picolino , thank you
@echo off
set VPNName="YourVPNConnectionName"
rasdial %VPNName%
It works perfectly thank you @picolino
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Script by webmaster at encode.ru https://encode.ru/threads/2084-batch-for-vpn-auto-reconnect-(8-1-or-10-tp)