by Njål

Permanent VPN connection in Windows

Windows does not really offer any good ways of setting up a permanent VPN connection that is stable.
People are literally loosing their minds over it.

We came up with 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. This will not be covered here.
At the client side
  1.  Set up a new VPN Connection. Just follow the usual “Connecto to a workplace” wizard. Make sure that the VPN connection works.
  2. After creating the connection – set these Redial properties. The redial functionality works as it should most of the time, but it’s not 100% trustable.
  3. Also – 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 hammer powershell time. Create c:pn.ps1and 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.

  7. Bingo! You now have a robust and permanent VPN Connection in windows. This works with PPTP, L2TP, SSTP and IKEv2, and have been tested on Windows 7 and Windows 2008 R2.
by Njål

Windows 7, Microsoft Security Essentials and PPTP VPN problemer

Satte opp en ny HP 6540b laptop for en kunde, og skulle konfigurere VPN tilkoblingen. La til vanlig PPTP som så mange ganger før (integrert i Windows) – og prøvde å koble til.. men nei. Laptopen nektet å koble til. Windows 7 foreslo at jeg skulle sjekke brannmur (på serveren), brukernavn og passord. Etter å ha restartet serveren på andre siden, to routere og installert alle windows oppdateringer på laptop’en.. så virket det fremdeles ikke.

Plutselig kom jeg på at jeg akkurat hadde installert Microsoft Security Essentials på laptop’en – like før jeg satte opp VPN tilkoblingen. Prøvde å disable real time protection, dette  hjalp ikke…  så jeg avinstallerte like godt, restartet og VOILA! Alt virket som en drøm. La inn AVG Free, ting virker fremdeles fint.

Kudos til Microsoft Security Essentials som ikke klarer å gjenkjenne/tillate sin egen PPTP klient å koble opp mot en server. Det var i allefall noe som skurret alvorlig i dette tilfellet.