?
Solved

VBScript to Add VPN Connections

Posted on 2005-03-14
13
Medium Priority
?
717 Views
Last Modified: 2008-03-03
I want to write a vbscript that will add VPN connections.  I have data (IP, login, password) for about 150 VPNs that I and my group of support techs need to connect to from time to time.  I'm looking for a way to add 150 VPN connections instead of adding them to Network and Dialup Connections manually through the Network Connection Wizard.  

I have looked at netsh, but it doesn't seem to support what I want.

I'm fairly script savvy, having written several scripts including a recent one to add about 1700 RDP connections.

Need a clue!  Thanks.
0
Comment
Question by:edmurphy2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
13 Comments
 
LVL 15

Accepted Solution

by:
Ralf Klatt earned 2000 total points
ID: 13538766
Hi,

Well, this one is about connecting pre-defined VPN Connections ... hmm, I think that 150 VPNs can easily be "pre-defined" ... and if, then this article could help a lot:

http://www.joshcook.net/2005/01/pptp-routing-interesting-traffic.asp


Best regards,
Raisor
0
 

Author Comment

by:edmurphy2005
ID: 13732555
No points for this non-answer.
0
 
LVL 15

Expert Comment

by:Ralf Klatt
ID: 13733343
Hi,

This is the script that can be found at the provided link:

'Program:      PPTP Route Addition Script
'Author:      Joshua R. Cook
'Website:      http://www.joshcook.net/
'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



What's wrong with it and why do you sound so offending, accusing me of having provided a "non-answer"?



Best regards,
Raisor
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:edmurphy2005
ID: 13768319
Thanks to all who try to help.  I didn't realize I was being so insensitive.  At the time I posted the question this was a priority.  I gave it a quick glance and commented before I gave it a full eval.  Then priorities changed, I've not checked my email, didn't have time to read it, personal business, my dog ate my...,  all the usual excuses.  When I have time to try it, hopefully by the end of the week, I'll post a "very good explanation" and/or give proper respect, as appropriate.
0
 

Author Comment

by:edmurphy2005
ID: 13769041
Let me re-state the question for clarification:

I want a script that will add a collection of objects to the Control Panel "Network and Dial-up Connections" folder.  The objects should be of type "Virtual Private Network".  The name, ip address, logon id, and password properties of each of the objects will be read from a file.  When clicked, each of the objects created by the script should establish a VPN connection.

I ran the script Raisor provided.  The "Network and Dial-up Connections" folder did not contain anything new.

All help is appreciated.

0
 
LVL 15

Expert Comment

by:Ralf Klatt
ID: 13769340
Hi,

@edmurphy2005 ... could you paste the script exactly as used? ... you may "XXXXXXX" any passwords if used in string format ...


Best regards,
Raisor
0
 

Author Comment

by:edmurphy2005
ID: 13778469
'***********************
'Task: Variable Creation

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

'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

0
 

Author Comment

by:edmurphy2005
ID: 13778498
Raisor's earliest reply seems to have redefined the question as "connecting a pre-defined VPN connection".  Whereas the original question is "define a VPN connection" or more specifically "define a collection of VPN connections".
0
 
LVL 15

Expert Comment

by:Ralf Klatt
ID: 13778549
Hi,

The script I presented was for giving you an idea or better: a basis on how to define a collection of VPN connections. I was also ready to assist you on developing the script to make it fit your needs even when this question was already closed by a moderator.

If you used the script as is, without any modifications -> it can surely not have worked ...

... anyway, you can not expect a "ready-to-use" script as this would be like doing your homework!


Best regards,
Raisor
0
 

Author Comment

by:edmurphy2005
ID: 13778589
I was hoping someone would know a way to add a VPN connection to Control Panel/Network and Dial-up Connections without going through the wizard.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question