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
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.

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:
octets = "192.168.50."
mask = ""

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

'msgbox "found the IP"

Set oShell = CreateObject ("")

'Here is where I add the route to the internal network of with the gateway of the VPN connection IP address.  ("cmd /c Route.exe Add MASK " & dwValue), 2
msgbox " You Are Now Connected to the VPN "
Set oShell = Nothing
End If