Answered Connect to Microsoft VPN in C#

  • Wednesday, July 16, 2008 9:58 PM
     
     
    I'm making an application that will connect to a Microsoft VPN, wait for it to finish, then start up a VNC connection to a remote PC.  Is there a way to connect to the VPN in code.  I know it's possible for Cisco by running a command in command prompt, but can Microsoft do a similar feat?

    Any thoughts would be greatly appreciated.

    Raptor354

All Replies

  • Thursday, July 17, 2008 12:20 PM
     
     
    I think what you're asking is after you create the connection like this:
    http://www.windowsecurity.com/articles/Configure-VPN-Connection-Windows-XP.html

    How do you call it programmactically?

    I don't know the answer to this, but.... all programs start off being called by a command interpreter.
    In windows quite often there are file associations with the objects' file extension for example the most famous is .exe.
    When the OS sees certain file extensions it just knows what to do. 

    So, what I'd try if I were you would be to determine the file extension type of the connection object.
    Then start a Process from C# that just calls the connection object.
    The OS should take care of the rest.  

    http://www.google.com/search?hl=en&q=C%23+process
    Javaman
  • Thursday, July 17, 2008 4:18 PM
     
     
    Yup.  That's my question all right.

    As it turns out, the VPN information is scattered in the registry and in some bizarre XML-like format (it doesn't appear to be XML exactly) deep in the depths of Windows - one of the areas with really long file names.  I found it by doing a scan of System32 using ExamDiff Pro.  Of course, everything's encoded, and I doubt Microsoft would tell me how to decode it - I would assume that would be explorer.exe's job.  However, I can make a shortcut to it somewhere and reference that, but it doesn't come back and tell me it's done.  And just in case, sleeping or pausing a thread for a certain amount of time is a really dirty way of doing it.

    I already know how to run a process: System.Diagnostics.Process.Start(<file name>, <args>).

    I'm beginning to seriously doubt the capabilities of the Microsoft VPN, and am considering making everyone switch to Cisco.  (But that wouldn't be good, now would it...)

    Just a thought, is there a way to intercept commands that windows is doing?  I've started working with linux due to XP not being sold anymore and Vista being a power hog (besides that, linux is free), and I'm pretty sure there's a way to see the background commands inside it.

    Eventually, I will be reprogramming for linux, but that may be down the road after we run out of the XP machine stockpile.

    Thanks for the response!

    Raptor354
    • Edited by Raptor354 Thursday, July 17, 2008 4:19 PM Fixed several grammerical errors
    •  
  • Thursday, July 17, 2008 5:17 PM
     
     
    In talking to a fellow programmer, he said that there was a DLL somewhere that allowed you to connect to a VPN, among other things.

    If anyone knows what DLL that might be, I'd be interested in any ideas.

    Thanks,

    Raptor354
  • Thursday, July 17, 2008 10:23 PM
     
     
    • Marked As Answer by Raptor354 Friday, July 18, 2008 3:07 PM
    • Unmarked As Answer by Raptor354 Tuesday, July 22, 2008 8:43 PM
    • Unmarked As Answer by Raptor354 Tuesday, July 22, 2008 8:43 PM
    • Unmarked As Answer by Raptor354 Tuesday, July 22, 2008 8:44 PM
    •  
  • Friday, July 18, 2008 3:07 PM
     
     
    Awesome!  That's exactly what I needed.

    Thanks Javaman!

    Raptor354
  • Tuesday, July 22, 2008 8:50 PM
     
     Answered Has Code
    For all of you who are looking to do a similar feat to what I did, the command is as follows:

    rasdial <vpn_name> <vpn_username> <vpn_password>

    To disconnect:

    rasdial <vpn_name> /d

    Thus, in usable terms, my line would look like this:

    System.Diagnostics.Process.Start("rasdial.exe""My_VPN My_Username My_Password"); 

    To disconnect from the VPN, simply use this line:

    System.Diagnostics.Process.Start("rasdial.exe""My_VPN /d"); 

    ~Raptor354
    • Marked As Answer by Raptor354 Tuesday, July 22, 2008 8:51 PM
    • Edited by Raptor354 Tuesday, July 22, 2008 8:53 PM Forgot to include disconnect commands
    •  
  • Wednesday, March 25, 2009 3:21 PM
     
     Proposed
     The dialer can be controlled in Windows using the RasDialer component in the DotRas project on CodePlex.

    http://www.codeplex.com/DotRas

    There's a documentation available for connecting and disconnecting entries there if you need help.
    • Proposed As Answer by Jeff Winn Wednesday, March 25, 2009 3:21 PM
    •  
  • Thursday, June 11, 2009 9:14 PM
     
     
    Can we connect to CISCO VPN Client using DotRas?
  • Friday, February 05, 2010 2:44 AM
     
     

    Generally speaking no it won't support third party connections. However, if you can dial the connection from Windows without using a 3rd party tool (aka, the Cisco VPN client) then DotRas can handle it as well.

  • Tuesday, July 24, 2012 5:52 PM
     
     
    four years later, this post is still beneficial.  i had never worked with "rasdial" in command prompt.  nice work.