connect.bat
rasdial myvpn
disconnect.bat
rasdial myvpn /DISCONNECT
....I assigned those two files a keyboard shortcut to run them and they work perfectly.
QUESTION: is it possible to make a single .bat that does the following:
if(connected)
disconnect
else
connect
On AndroidTap on the Settings icon in the upper-left corner and choose VPN connection. Tap Auto-connect. Select when you want to establish a VPN connection automatically. Tap Auto-connect to and select the server you want to connect automatically.
This does technically work, but rasdial requires you enter the username and password in this format: rasdial $vpnName $Username $password.... Even if the password is saved, it requires you to have those parameters in plaintext.
Based on ping
in case the VPN server IP is always the same:
ping -n 1 1.2.3.4 && rasdial myvpn /disconnect || rasdial myvpn
Replace 1.2.3.4 with your VPN server ip (use ipconfig /all
when connected) and put this in your batch file or directly in the shortcut properties prepending with cmd /c
in the latter case.
Based on connection name:
ipconfig|find/i "myvpn" && rasdial myvpn /disconnect || rasdial myvpn
Replace myvpn
with your VPN connection name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With