Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I run this script?

Status
Not open for further replies.

random260

Programmer
Mar 11, 2002
116
US
I was pointed to a very good article by Josh Cook (full article at


with the info I am talking about 1/2 way down the page)

about routing and VPN connections. He included in this page a very simple script - but neglected to tell us vbscript dummies HOW to execute the doggone thing. Can someone take a look at this and tell me if it should be run from command line (saved as a .bat? compiled as an .exe?), or saved as an HTML page and loaded , whatever? The full script is also in the article referenced above, but here it is (comments and all): (***NOTE*** The lines are longer then what will fit in this window - in order to see this in readable form (and not confuse comments with script lines) please copy and paste it in Notepad or something.)

'Program: PPTP Route Addition Script
'Author: Joshua R. Cook
'Website: 'Date: 1.13.2005

'***********************
'Task: Variable Creation

'In Windows, the name of the VPN connection as it is appears in Network Connections
VPNConnection = "My Work VPN"

'The username for the VPN connection
VPNUsername = "username"

'The password for the VPN connection
VPNPassword = "password"

'The IP range that is provided to PPTP clients, without that last octet (this is used for matching purposes)
PPTPNetwork = "192.168.1."

'The route command that should be executed, without the gateway
' - route add *network* mask *netmask*
RouteCommand = "route add 10.0.0.0 mask 255.255.255.0"

'*********************************
'Task: Establish Dialup Connection

Set Shell = CreateObject("WScript.Shell")
Shell.Run "Rasdial " & VPNConnection & " " & VPNUsername & " " & VPNPassword, 6, True
Set Shell = Nothing

'*********************************
'Task: Obtain *Correct* IP Address

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")

For Each objAdapter In colAdapters

If InStr(objAdapter.IPAddress(0), PPTPNetwork) > 0 Then VPNIPAddress = objAdapter.IPAddress(0)

Next

Set colAdapters = Nothing
Set objWMIService = Nothing

'*************************
'Task: Add Route Statement

Set Shell = CreateObject("WScript.Shell")
Shell.Run RouteCommand & " " & VPNIPAddress, 6, True
Set Shell = Nothing
 
Save it as a .vbs file then double click it.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
That makes perfect sense. One more question - can this cript execute a .bat file at the end of it? I have a batch file in the root of C: that I have to run to connect network drives after the VPN connects. If I can have the script execute that after it sets the routes that would eliminate another step. If it can, what do I add to the script?

Thanks
 
Shell.Run "C:\TEmp\YouBatchFile.BAT", 6, True

This is before you set Shell = Nothing
 
Why don't you just add the mappings into the same script? Running batch files is less efficient.

Find sample code for mappings in my FAQ faq329-5798.

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top