-4

I want to connect to Cisco VPN via C#. Researching all over the internet doesn't return code sample that is workng. I however have found a way to connect via the command line but I don't know how I can get this to the commandline programmatically in C#.

vpnclient connect user dennis pwd dennisPassword toVPN

How can I do this in C# and is there any other better method that this? And do I have to have the Cisco VPN Client installed first?

Lots of thanks.

Dev
  • 1,146
  • 2
  • 19
  • 30
  • http://stackoverflow.com/questions/512365/programatially-determine-if-cisco-vpn-client-is-connected?rq=1 – Sam Axe Mar 30 '15 at 21:56
  • @Sam am using C# and from the link provided it looks like to code is for C. I also want to connect to the VPN not just determine if VPN is connected. – Dev Mar 31 '15 at 05:57
  • Wow. You really didn't read that question and its answers at all did you. – Sam Axe Mar 31 '15 at 06:23
  • I did check and yes the answer would have been applicable in my case if it was aimed for C#. The question in that link isn't language specific as pointed in the comment below it. The codes provided look like the answers are based on C. Sorry am just a beginner and if am not getting it, kindly point it out. Kindly help me .out, thanks – Dev Mar 31 '15 at 13:37
  • Dennis - the relevant portion there is that the Cisco VPN client provides an API. You will have to consult the documentation to understand how to use it, but it's always better to use the provided API. C# can consume C-style APIs via P/Invoke. – Sam Axe Apr 01 '15 at 01:14

2 Answers2

1
System.Diagnostics.Process.Start("vpnclient connect user dennis pwd dennisPassword toVPN");

There is an overload that takes a ProcessStartInfo if you need to more exactly control how the process starts.

https://msdn.microsoft.com/en-us/library/system.diagnostics.process.start%28v=vs.110%29.aspx

Bradley Uffner
  • 16,641
  • 3
  • 39
  • 76
  • Here is my code from what you have advised. However it throws an Exception that states that the program wasn't found yet I retrieve path at runtime and when I check there is the program vpnclient.exe `string path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + @"\Cisco Systems\VPN Client\"; System.Diagnostics.Process.Start(path + "vpnclient.exe connect user validuser pwd validpassword validentryname"); ` – Dev Mar 31 '15 at 05:57
1

Try https://stackoverflow.com/a/35322011 or try

System.Diagnostics.Process.Start("vpnclient","connect user dennis pwd dennisPassword toVPN");
Community
  • 1
  • 1
Yamir
  • 151
  • 1
  • 3