VPN – Visual Basic 2010 – Framework 4

Di seguito del codice Visual Basic che illustra come eseguire la connessione e disconnessione di una VPN configurata nel sistema windows.

Si utilizza l’applicazione rasdial.exe per gestire le due operazioni.

Imports System.IO

Public Class Form1

    Private Sub bnConnect_Click(sender As System.Object, e As System.EventArgs) Handles bnConnect.Click

        ' Start the child process.
        Dim p As Process
        p = New Process

        p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        p.StartInfo.FileName = "rasdial"
        p.StartInfo.Arguments = "<nome_connessione_VPN> <username> <password>"
        p.Start()

        p.WaitForExit()
        MsgBox(p.ExitCode)
        p.Close()

    End Sub

    Private Sub bnDisconnect_Click(sender As System.Object, e As System.EventArgs) Handles bnDisconnect.Click

        ' Start the child process.
        Dim p As Process
        p = New Process

        p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        p.StartInfo.FileName = "rasdial"
        p.StartInfo.Arguments = "<nome_connessione_VPN> /disconnect"
        p.Start()

        p.WaitForExit()
        MsgBox(p.ExitCode)
        p.Close()

    End Sub
End Class
This entry was posted in Microsoft .NET Visual Basic, Programming Languages. Bookmark the permalink.