Submitted By: Omar Droubi-Marathon Solutions

Adds a route after a VPN is connected. The VPN connection is configured to not use the default gateway on the remote network.

Visual Basic
Edit|Remove
const HKEY_LOCAL_MACHINE = &H80000002

' This script is used to add a route to the internal network after a VPN connection has been established.
' The VPN connection used is configured to not use the default gateway on the remote network.
' The client wishes to have his users connect to the VPN on the internal network- and browse the Internet from their broadband connection.
' This basically enables split tunnelling-which is not advisable but maybe necessary in some cases as this one did.
'http://www.microsoft.com/technet/community/columns/cableguy/cg1003.mspx


strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces"

objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

For Each subkey In arrSubKeys

	intKey = subkey
'msgbox "intkey: " & intKey
	strKeyPath1 = strKeyPath & "\" & intKey
'msgbox "strKeyPath1: " & strKeyPath1

strValueName = "DhcpIPAddress"
strValueName2 = "DhcpSubnetMask"
objReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath1,strValueName,dwValue
objReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath1,strValueName2,dwValue2

'WScript.Echo "DHCPIPAddress: "& dwValue

'WScript.Echo "DhcpSubnetmask: "& dwValue2

' My variables here are used to scan the registry to find the actual VPN connection IP address- since the VPN IP is on the 192.168.50 network
' And always gets a host mask- this is how I found and isolated the connection IP address to use as my gateway for the internal network
' If you want to know more check out this article: http://www.microsoft.com/technet/community/columns/cableguy/cg1003.mspx
octets = "192.168.50."
mask = "255.255.255.255"

If Instr(1,dwValue, octets, 1) AND mask = dwValue2 Then

'msgbox "found the IP"

Set oShell = CreateObject ("WSCript.shell")

'Here is where I add the route to the internal network of 10.10.0.0 with the gateway of the VPN connection IP address.

oShell.run  ("cmd /c Route.exe Add 10.10.0.0 MASK 255.255.0.0 " & dwValue), 2
msgbox " You Are Now Connected to the VPN "
Set oShell = Nothing
wscript.quit
End If
Next