Permanent VPN connection in Windows

Windows does not really offer any good ways of setting up a permanent VPN connection that is stable.

A pretty nice solution to this problem by combining

  • Windows Powershell
  • Windows VPN Client
  • Windows Task scheduler
At the server side make sure your VPN Server is set up and working.
At the client side:

1. Set up a new VPN Connection. Just follow the usual “Connect to a workplace” wizard. Make sure that the VPN connection works.
2. After creating the connection – set Redialing properties.

  • Redeal attempts - 99
  • Time between redial attempts - 1 minute
  • Idle time before handing up - never
  • Redial if line is dropped - ticket

3. Uncheck “Use default gateway on remote network” – in order to prevent all network/internet trafic to go through the VPN (unless this is what you want).

4.Since the Redial functionality of the VPN Connection isn’t trustable – it’s best to deal with this yourself. It’s powershell time. Create c:\vpn.ps1 and add the following:

$ip = "10.20.30.40"
$result = gwmi -query "SELECT * FROM Win32_PingStatus WHERE Address = '$ip'"
if ($result.StatusCode -eq 0) {
    Write-Host "$ip is up."
}
else{
    Write-Host "$ip is down."
    Write-Host "Disconnecting..."
    rasdial.exe DegreeVPN /DISCONNECT
    Write-Host "Connecting..."
    rasdial.exe DegreeVPN vpnUsername vpnPassword12345
}

The script pings an IP that should be available through the VPN. If the ping is unsucecssfull – the connection is reestablished. You can also set up routes here (and get notifications by email every time the VPN was disconnected) if you add a few more lines to the script.

5. Start up a powershell and type “Set-ExecutionPolicy Unrestricted” order to allow the script to be executed.

6. Schedule this script to execute at startup (no user/login necessary) and also every 5 minutes.


AUST IT - Computer help out of hours, when you need it most.

Find out why we do it for less.

About

AUST IT will help you resolve any technical support issues you are facing onsite or remotely via remote desktop 24/7. More...

Contacts

Reservoir, Melbourne,
3073, VIC, Australia

Phone: 0422 348 882

This email address is being protected from spambots. You need JavaScript enabled to view it.

Sydney: 0481 837 077

Connect

Join us in social networks to be in touch.

Newsletter

Complete the form below, and we'll send you our emails with all the latest AUST IT news.