check for cisco vpn connection...enabled or disabled

I have a CISCO Vpn anyconnect secure mobility client.
v 3.1.02040

Does any one know of a way in vba to check and see if a vpn connection is established or not ?

Who is Participating?
als315Connect With a Mentor Commented:
You can ping far side of vpn connection. Details of WMI Win32_PingStatus you can find here:
Vba version:
Sub test()
If Ping("") Then
    MsgBox "Passed", vbOKOnly
    MsgBox "Failed", vbOKOnly
End If
End Sub
Public Function Ping(ByVal ComputerIP As String) As Boolean
    'You can use also name of computer
    ' Return TRUE, if pin was successful
   Dim oPingResult As Variant
    For Each oPingResult In GetObject("winmgmts://./root/cimv2").ExecQuery _
        ("SELECT * FROM Win32_PingStatus WHERE Address = '" & ComputerName & "'")
        If IsObject(oPingResult) Then
            If oPingResult.StatusCode = 0 Then
                Ping = True
                'Debug.Print "ResponseTime", oPingResult.ResponseTime 'You can also return ping time
               Exit Function
            End If
        End If
End Function

Open in new window

FordraidersAuthor Commented:
Thanks !
FordraidersAuthor Commented:
als315, This is passing any test i give it.  Off or on vpn ?
FordraidersAuthor Commented:
nm, this worked for now.
Function IsVPNConnected()
   IsVPNConnected = False
   sComputer = "."

   Set oWMIService = GetObject("winmgmts:\\" _
    & sComputer & "\root\CIMV2")

   Set colItems = oWMIService.ExecQuery( _
    "SELECT * FROM Win32_NetworkAdapterConfiguration", , 48)

   For Each objItem In colItems

'Please check description of your VPN Connection by running command "ipconfig /all" on command-line.

    If (InStr(objItem.Description, "AnyConnect")) Then
     IsVPNConnected = objItem.IPEnabled
    End If


   If (IsVPNConnected) Then
    IsVPNConnected = MsgBox("I am Connected to VPN.")
    IsVPNConnected = MsgBox("I am Not Connected to VPN.")
   End If

End Function
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.