Launch VPN

569 views
Skip to first unread message

CoachBarker

unread,
Aug 8, 2007, 6:42:47 PM8/8/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I am creating a Remote Desktop application for work and one of the
things I need to be able to do is launch the VPN from inside the
application. When
installed the VPN only places a short cut on the desk top and I can't
target
that to launch it. This application is being created in Visula Studio
2005
usin vb.net. I can call

Process.Start("iexplore") to launch internet exporer

so the VPN would be
Process.Start(" ") for the vpn.

Has anyone else had to do anything like this?

Thanks
CoachBarker

Alexander Higgins

unread,
Aug 10, 2007, 4:00:23 AM8/10/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
1) Go to your network connection folder and find the connection name
for the vpn connection. For example, "WorkVpn"
2) Rasdial.exe - "Work Vpn" username password /domain:domainName
3) To diconnect rasdial /disconnect

That will fire the VPN and log you in. However, the is really no way
to tell if you have been connected or the remote server's drives are
available. So I pipe the output of the Rasdial to a text file and
then read it to make sure I have connected.

Here is an HTA file I use, that launches a VPN Connection and then
Maps a network drive on the remote server.


<html>
<head>


<script language=vbscript type=text/vbscript>
'========================================================
'
' Script copyright by Alexander Higgins 2007
' You may use this script as long as this disclaimer stays in
place.
' For more information or examples on how to modify this script
' Visit http://alexanderhiggins.com
'
'========================================================
function wshNetwork()
set wshNetwork = createObject("wscript.Network")
end function

function shell()
set shell=createObject("wscript.shell")
end function

function fso()
set fso=createobject("scripting.filesystemobject")
end function


sub main()
div.innerHTML = ""
div.innerHTML = div.innerHTML & "Connection Successful..."
connect pwd, uname
div.innerHTML = div.innerHTML & "<br>Map Network Drives Successful..."
If success=true then

stlogin.style.display="none"
mapdrives pwd, uname
div.innerHTML = div.innerHTML & "<br><br><input type='button'
onclick='disconnect' value='Disconnect'/>"
'msgbox("When finished press ""OK"" to Disconnect")
'disconnect
Else
'exit sub
End if
end sub

sub connect(pwd, uname)

if fso.fileExists("c:\log.txt") then
fso.DeleteFile("C:\log.txt")
end if
cmd = "rasdial " & chr(34) & "VpnConnectionName" & chr(34) & " " &
uname.value & " " & pwd.value & " /domain:domainName"
'msgbox cmd
shell.run "cmd /c " & cmd & " >> c:\log.txt", ,true
end sub

sub disconnect()

cmd = "rasdial /disconnect"
shell.run cmd
stlogin.style.display="block"
div.innerhtml=""
window.close()
end sub

Sub mapdrives(pwd, uname)
if fso.DriveExists("l:") then
wshNetwork.RemoveNetworkDrive "l:"
end if
DO until fso.driveExists("l:")
on error resume next
wshNetwork.MapNetworkDrive "l:", "\\10.10.10.87\e$"

loop
end sub
function success()
success= false
do until fso.fileExists("c:\log.txt")
loop
set alog = fso.openTextFile("C:\log.txt")
on error resume next
line = alog.readline
str = ""
do while not alog.atEndOfStream
line = alog.readline
str = str & line
if instr(line, "success") then
success = true
end if
loop
if success = false then
div.innerHTML = "<h1>Connection Error</h1><p align=left>" + str + "</
p>"

end if


end function
</script>
<style>
body, div, p, td { font-family:arial;font-size:12px;}
body {
background: url(c:\header_med.jpg) top center no-repeat fixed;
scrollbars:none}
</style>
</head>
<body onload="window.resizeto 400, 500" scroll=no>
<br><br><BR><BR>
<h1 align=center style="font-size:20px;"> VPN Utility</h1>
<div id=stlogin>

<b>Username</b><br>
<input type="text" id="uname">
<br><br>
<b>Password</b>
<br>
<input type="text" id="pwd" /><p align=center>
<input type="button" value="Connect" onclick="main" /></p>
</div>
<div align=center id=div><p align=left>Use this Utility to access the
VPN. To begin, enter your
username and password and click "Connect'.
<BR><BR> After logging in, The server &nbsp;e: drive will be
available as your l: drive in "My Computer". You can also then access
other network resources.</p> </div>
</body>
</html>


Hope this helps,

Alex Higgins

CoachBarker

unread,
Aug 10, 2007, 5:55:03 AM8/10/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting

All I need to do is launch the VPN Login dialog box. The Username and
password is entered there, once the conection is made I can check it
in this code in the application.

Public Sub VPNRunning()
Try
Dim pppAddress() As
System.Net.NetworkInformation.NetworkInterface =
System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces
For Each cInterface As
System.Net.NetworkInformation.NetworkInterface In pppAddress
If cInterface.NetworkInterfaceType =
Net.NetworkInformation.NetworkInterfaceType.Ppp Then
If pppIPAddresses =
(cInterface.GetIPProperties.UnicastAddresses.Item(0).Address.ToString().Remove(10,
4)) Then
TextBox7.Text =
(cInterface.GetIPProperties.UnicastAddresses.Item(0).Address.ToString())
MsgBox("The VPN is running and the PPP Adapter
IP Address is: " &
(cInterface.GetIPProperties.UnicastAddresses.Item(0).Address.ToString().Remove(10,
4)))
'Else
'MsgBox("VPN is not running")
End If
End If
Next
MsgBox("VPN is not running, Please Log into the VPN")
Process.Start("rasphone.exe")

Catch ex As Exception

End Try
End Sub

This compares the PPP Adapter IP Address to a hardcoded example in the
appplication.


Process.Start("rasphone.exe") starts the Network Connections dialog
box, and I can click the Connect button after selecting the Network
Connection from the combo box and open the dialog box for the VPN. So
what I need is to use

Process.Start("rasphone.exe", "path here")

So if anyone would like to give it I shot I would be more than happy
to send them the VPN.exe and let them find the rest of the path.

Thanks for all the previous advice
CoachBarker

On Aug 10, 4:00 am, Alexander Higgins <alexhiggins...@hotmail.com>
wrote:


> 1) Go to your network connection folder and find the connection name
> for the vpn connection. For example, "WorkVpn"
> 2) Rasdial.exe - "Work Vpn" username password /domain:domainName
> 3) To diconnect rasdial /disconnect
>
> That will fire the VPN and log you in. However, the is really no way
> to tell if you have been connected or the remote server's drives are
> available. So I pipe the output of the Rasdial to a text file and
> then read it to make sure I have connected.
>
> Here is an HTA file I use, that launches a VPN Connection and then
> Maps a network drive on the remote server.
>
> <html>
> <head>
>
> <script language=vbscript type=text/vbscript>
> '========================================================
> '
> ' Script copyright by Alexander Higgins 2007
> ' You may use this script as long as this disclaimer stays in
> place.
> ' For more information or examples on how to modify this script

> ' Visithttp://alexanderhiggins.com

> <BR><BR> After logging in, The server e: drive will be


> available as your l: drive in "My Computer". You can also then access
> other network resources.</p> </div>
> </body>
> </html>
>
> Hope this helps,
>
> Alex Higgins
>
> On Aug 8, 6:42 pm, CoachBarker <barke...@morrisville.edu> wrote:
>
>
>
> > I am creating a Remote Desktop application for work and one of the
> > things I need to be able to do is launch the VPN from inside the
> > application. When
> > installed the VPN only places a short cut on the desk top and I can't
> > target
> > that to launch it. This application is being created in Visula Studio
> > 2005
> > usin vb.net. I can call
>
> > Process.Start("iexplore") to launch internet exporer
>
> > so the VPN would be
> > Process.Start(" ") for the vpn.
>
> > Has anyone else had to do anything like this?
>
> > Thanks

> > CoachBarker- Hide quoted text -
>
> - Show quoted text -

Alexander Higgins

unread,
Aug 16, 2007, 12:21:05 AM8/16/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Look at the example above using rasdial.exe as opposed to rasphone

I would suggest making a form and opening it using showdialog to
collect the username and password for the connection.

When the user clicks the "Connect" button, call
Process.Start("rasdial.exe, "VpnConnectionName UserName Password" )


On Aug 10, 5:55 am, CoachBarker <barke...@morrisville.edu> wrote:
> All I need to do is launch the VPN Login dialog box. The Username and
> password is entered there, once the conection is made I can check it
> in this code in the application.
>
> Public Sub VPNRunning()
> Try
> Dim pppAddress() As
> System.Net.NetworkInformation.NetworkInterface =
> System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces
> For Each cInterface As
> System.Net.NetworkInformation.NetworkInterface In pppAddress
> If cInterface.NetworkInterfaceType =
> Net.NetworkInformation.NetworkInterfaceType.Ppp Then
> If pppIPAddresses =

> (cInterface.GetIPProperties.UnicastAddresses.Item(0).Address.ToString().Rem­ove(10,


> 4)) Then
> TextBox7.Text =
> (cInterface.GetIPProperties.UnicastAddresses.Item(0).Address.ToString())
> MsgBox("The VPN is running and the PPP Adapter
> IP Address is: " &

> (cInterface.GetIPProperties.UnicastAddresses.Item(0).Address.ToString().Rem­ove(10,

> > - Show quoted text -- Hide quoted text -

Reply all
Reply to author
Forward
0 new messages