Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, I am creating VPN client for my team. I have completed L2TP, PPTP and IKEv2 section. Now I need to implement OpenVPN. Can somebody help me with creating OpenVPN client using VB.net. I have the code almost. However, it is not working well for me.

Here process.start throws file not found.
Shell not working..showing is not a method
Interaction.shell working but not connecting

What I have tried:

VB.NET
Public Sub myConnection()
        proto = "udp"


        ' UDP Config File

        serverf = "--client --dev tun --remote " & IPServer & " --proto " & proto & " --port " & "1194" & "  --lport " & "1194" & _
    "--keepalive 20 60 --reneg-sec 432000 --resolv-retry infinite --cipher AES-128-CBC  --fast-io --pull --tun-mtu 1500 --auth-user-pass data\user.txt " & _
    "--persist-key --persist-tun --ca data\vpnbook.ca --verb 3 --redirect-gateway --route-delay 2 --explicit-exit-notify 2 " & _
    " --log data\logfile.tmp --status data\status.dat 1 "


        SelectServer = serverf

    End Sub


VB.NET
Private Sub ovconnection()
        loadsettings()
        tnew = 0
        Try

            pingurl = " -t"

        Catch ex As Exception

        End Try
        If lb_con.Content = "Connect" Then
            If tb1_server.Text = "" Then
                MessageBox.Show("Please select your server!")
            Else
               
                lb1.Content = "Connecting"
                lb_con.Content = "Connecting"
                myConnection()
                process.Start(Forms.Application.StartupPath & "\bin\openvpn " & SelectServer, AppWinStyle.Hide)
            End If
        ElseIf lb_con.Content = "Disconnect" Then
            Dim g As String
            g = "taskkill /f /im openvpn.exe"
            Interaction.Shell("cmd /c" & g, vbHide)
            g = "taskkill /f /im ping.exe"
            Interaction.Shell("cmd /c" & g, vbHide)
            lb1.Content = "Disconnected"
            lb_con.Content = "Connect"
        ElseIf lb_con.Content = "Connecting" Then
            If MsgBox("Do You want to Disconnect VPN", MsgBoxStyle.YesNo, "VPN") = vbYes Then
                c = 0
                Dim g As String
                g = "taskkill /f /im openvpn.exe"
                Interaction.Shell("cmd /c" & g, vbHide)
                g = "taskkill /f /im ping.exe"
                Interaction.Shell("cmd /c" & g, vbHide)
                lb1.Content = "Disconnected"
                lb_con.Content = "Connect"
            End If
        End If
    End Sub
Posted
Updated 3-Jul-18 20:00pm
v2

1 solution

It means openvpn was not found in the specified directory. You could log Forms.Application.StartupPath & "\bin\openvpn" and verify it contains the path you expect.
 
Share this answer
 
Comments
Member 13857021 4-Jul-18 1:57am    
But when I remove tge select server option, the openvpn file opens..so it should be something with the code, right

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900